Base solution for your next web application

Activities of "sayram"

As become a beginner i can use Abp but i want to use full functional, write better code and understand things how they work. Documentations not for beginners and i have a lot of questions that confuses me.

So can anybody please explain Why, Where, When, How i have to use AutoMap, AutoMapTo, AutoMapFrom?

And i need real sample about Permissions and settings usage. Change, Create, Update from control panel. How you guys done these?

Thank you.

Yea i saw it. But, what if i want to get UserId with providerKey (in my case to check if visitor registered be4.)

How to query UserLogins? with UserManager? I'm confused.

<cite>hikalkan: </cite> You can not return IQueryable from application service method. Just use ToList() after Where condition.

changed code below

...
            var categories = _categoryRepository.GetAll().Where(c => c.CategoryState == state.ToString());
...

to

...
            var categories = _categoryRepository.GetAll().Where(c => c.CategoryState == state.ToString()).ToList();
...

This time a get this error.

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

This is the Stack trace

[ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.]
   System.Data.Entity.Core.Objects.ObjectContext.get_Connection() +91
   System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +273
   System.Data.Entity.Core.Objects.ObjectQuery`1.Execute(MergeOption mergeOption) +83
   System.Data.Entity.Core.Objects.DataClasses.EntityCollection`1.Load(List`1 collection, MergeOption mergeOption) +203
   System.Data.Entity.Core.Objects.DataClasses.EntityCollection`1.Load(MergeOption mergeOption) +51
   System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.Load() +59
   System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.DeferredLoad() +438
   System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty(TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject) +165
   System.Data.Entity.Core.Objects.Internal.<>c__DisplayClass7`2.&lt;GetInterceptorDelegate&gt;b__1(TProxy proxy, TItem item) +205
   System.Data.Entity.DynamicProxies.Category_93B8F10007F4823D6C15308F82C291EDF6CC0E4BAC3D32B099E0561F771A5140.get_SubCategories() +75
   CallSite.Target(Closure , CallSite , Object ) +189
   System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +517
   ASP.&lt;&gt;c__DisplayClassd.&lt;PrintCategories&gt;b__c(TextWriter __razor_helper_writer) in c:\Users\saYRam\Documents\Visual Studio 2013\Projects\Index Projects\Index.Web\Areas\Administrator\Views\Category\AddCategory.cshtml:82
   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
   System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
   System.Web.WebPages.WebPageBase.Write(HelperResult result) +53
   ASP._Page_Areas_Administrator_Views_Category_AddCategory_cshtml.Execute() in c:\Users\saYRam\Documents\Visual Studio 2013\Projects\Index Projects\Index.Web\Areas\Administrator\Views\Category\AddCategory.cshtml:91
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +270
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +122
   System.Web.WebPages.StartPage.RunPage() +63
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +100
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +131
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9723757
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

i really did not understood why and where i made mistake.

I have a CategoryService I'm using a method like below

public IEnumerable<Category> GetCategories(ContentState state)
        {
            var categories = _categoryRepository.GetAll().Where(c => c.CategoryState == state.ToString());

            //var categories = _categoryRepository.GetAllList(c => c.CategoryState == state.ToString());
            return categories;
        }

this is the AddCategory method in controller

public ActionResult AddCategory()
        {
            var categories = _categoryService.GetCategories(ContentState.Published);
            var viewModel = new CreateCategoryViewModel
            {
                Categories = categories.ToSelectListItems(-1),
            };

            return View(viewModel);
        }

Btw this is the ContentState

public enum ContentState
    {
        Published,
        Unpublished,
        Trashed,
        Pending
    }

and thi is the Category entity

public partial class Category : Entity
    {
        public Category()
        {
            this.SubCategories = new List<Category>();
            this.Videos = new List<Video>();
        }

        public int? ParentId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string MetaKeys { get; set; }
        public string MetaDescription { get; set; }
        public string CategoryState { get; set; }
        public virtual ICollection<Category> SubCategories { get; set; }
        public virtual Category ParentCategory { get; set; }
    }

Viewmodel

public class CreateCategoryViewModel 
    {
        public int Id { get; set; }
        public int? ParentId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string MetaKeys { get; set; }
        public string MetaDescription { get; set; }
        public string CategoryState { get; set; }
        public string Button { get; set; }
        //public string ActionMessage { get; set; }

        public IEnumerable<SelectListItem> Categories { get; set; }

    }

this is the where i get the error

@helper PrintCategories(dynamic categories)
{
    foreach (var item in categories)
    {
        @item.Title
        <br />
        var subCategories = item.SubCategories;
        if (subCategories != null && subCategories.Count > 0)
        {
            PrintCategories(subCategories);
        }
    }
}
                            <div class="form-group">
                                <div class="col-lg-10">
                                    @PrintCategories(Model.Categories)
                                </div>
                            </div>

so when im trying to access navigation property i get this error

The operation cannot be completed because the DbContext has been disposed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The operation cannot be completed because the DbContext has been disposed.

Stack Trace

[InvalidOperationException: The operation cannot be completed because the DbContext has been disposed.]
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +762
   System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() +28
   System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator() +52
   ASP.<>c__DisplayClassd.<PrintCategories>b__c(TextWriter __razor_helper_writer) in c:\Users\saYRam\Documents\Visual Studio 2013\Projects\Index Projects\Index.Web\Areas\Administrator\Views\Category\AddCategory.cshtml:82
   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
   System.Web.WebPages.WebPageBase.Write(HelperResult result) +80
   ASP._Page_Areas_Administrator_Views_Category_AddCategory_cshtml.Execute() in c:\Users\saYRam\Documents\Visual Studio 2013\Projects\Index Projects\Index.Web\Areas\Administrator\Views\Category\AddCategory.cshtml:71
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
   System.Web.WebPages.StartPage.RunPage() +17
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +173
   System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9723757
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

I think its related Lazy Loading which is i realy scared when i hear its name. I have no idea how can i get rid of this.

ok sorry found InsertAndGetId method :)

bunu akıl ettiğn için teşekkürler dostum. Mükemmellik ayrıntılarda gizlidir. :)

In my categoryService im adding category entity with this codes.

    public void CreateCategory(Category entity)
    {
       _categoryRepository.Insert(entity);
    }

I need the Id number of the inserted entity. How to get it? Ty.

I dont want to use GetCategoryByTitle or something like that because there can be same named categories.

I agree i need a sample module project like blog or something like that. Do anyone can share a sample module project to understand?

Yes i saw this when i check my codes. I remembered now. I was trying ReSharper shortcuts (Introduce Field) Sorry for unnecessary topic.

K. I'm trying to build my web application. It's a normal Mvc web application.

Well i created a model named Category. here it is.

public class Category : Entity<int>, ISoftDelete, IPassivable
    {
        public Category()
        {
            this.SubCategories = new List<Category>();
            IsActive = true;
            IsDeleted = false;
        }

        [ForeignKey("ParentId")]
        public int? ParentId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public bool IsActive { get; set; }
        public bool IsDeleted { get; set; }
        public virtual ICollection<Category> SubCategories { get; set; }
        public virtual Category ParentCategory { get; set; }
    }

well i created ICategoryService interface and CategoryService class.

public interface ICategoryService : IApplicationService
    {
        GetCategoryOutput GetCategories(GetCategoryInput input);
        void UpdateCategory(UpdateCategoryInput input);
        void CreateCategory(CreateCategoryInput input);
    }
public class CategoryService : ApplicationService, ICategoryService
    {
        private readonly  ICategoryRepository _categoryRepository;
        private readonly ICategoryService _categoryService;
        
        public CategoryService(ICategoryService categoryService, ICategoryRepository categoryRepository)
        {
            _categoryService = categoryService;
            _categoryRepository = categoryRepository;
        }

        public GetCategoryOutput GetCategories(GetCategoryInput input)
        {
            var categories = _categoryRepository.GetCategories(input.IsActive, input.IsDeleted);

            return new GetCategoryOutput
            {
                Categories = Mapper.Map<List<CategoryDto>>(categories)
            };
        }

        public void CreateCategory(CreateCategoryInput input)
        {
            Logger.Info("Creating a category for input: " + input);

            //Creating a new category with given input's parametes
            var category = new Category
            {
                ParentId = input.ParentId,
                Title = input.Title,
                Description = input.Description
            };

            if (input.ParentId.HasValue)
            {
                category.ParentCategory = _categoryRepository.Load((input.ParentId.Value));
            }

            _categoryRepository.Insert((category));
        }


        public void UpdateCategory(UpdateCategoryInput input)
        {
            Logger.Info("Updatinga category for input: " + input);

            var category = _categoryRepository.Get(input.CategoryId);


            if (input.ParentId.HasValue)
            {
                category.ParentCategory = _categoryRepository.Load((input.ParentId.Value));
            }

            //We even do not call Update method of the repository.
            //Because an application service method is a 'unit of work' scope as default.
            //ABP automatically saves all changes when a 'unit of work' scope ends (without any exception).
        }
    }

I've added an Area named Administrator and a Controller named CategoryController.

public class CategoryController : BisahneControllerBase
    {
        private ICategoryService _categoryService;

        public CategoryController(ICategoryService categoryService)
        {
            _categoryService = categoryService;
        }

        //
        // GET: /Administrator/Category/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(CategoryDto categoryDto)
        {
            return View();
        }

	}

when i run the application and browse the Administrator/Category/Create i'm getting an error like below

Can't create component 'Bisahne.Categories.CategoryService' as it has dependencies to be satisfied.

'Bisahne.Categories.CategoryService' is waiting for the following dependencies:

  • Service 'Bisahne.Categories.ICategoryService' which points back to the component itself. A dependency cannot be satisfied by the component itself, did you forget to register other components for this service?

Do i have to register something anywhere?

Showing 21 to 30 of 30 entries