Base solution for your next web application

Activities of "mcmaestro"

I figured out the issue. My Template entity was being referenced in other database tables but deleting entities with casade was disabled for this table. So the database was throwing an error but it was never making it to the fronted.

Thanks for your help.

For some reason when I try to delete an entity object it will not actually delete from the database.

For Example here is my Application Service TemplateAppService, I have a method that called DeleteTemplate and after it runs successfully, I know in the database that the record is not actually delete.

I have even tried to run SaveChanges method manually.

Any help would be appreciated.

Thanks,

public class TemplateAppService : KameleonAppServiceBase, ITemplateAppService
    {
        private readonly IRepository<Template, long> _templateRepository;
        private readonly IRepository<TemplateStatus> _templateStatusRepository;
        private readonly IRepository<TemplateCategory> _templateCategoryRepository;
        private readonly ISvgCreativeAppService _svgCreativeAppService;

        public TemplateAppService(IRepository<Template, long> templateRepository, ISvgCreativeAppService svgCreativeAppService, IRepository<TemplateStatus> templateStatusRepository, IRepository<TemplateCategory> templateCategoryRepository)
        {
            _templateRepository = templateRepository;
            _svgCreativeAppService = svgCreativeAppService;
            _templateStatusRepository = templateStatusRepository;
            _templateCategoryRepository = templateCategoryRepository;
        }

        public async Task<long> CreateTemplate(TemplateInput input)
        {
            var template = new Template();

            input.MapTo(template);

           var id  =  await _templateRepository.InsertAndGetIdAsync(template);

          
               await _svgCreativeAppService.CreateSvgCreative(
                      new SvgCreativeInput
                      {
                          Name = template.Name,
                          TemplateId = id,
                          BaseProductId = input.BaseProductId
                      }
                  );

               await CurrentUnitOfWork.SaveChangesAsync();          

           return id;
        }

        public async Task UpdateTemplate(TemplateInput input)
        {
            var template = await _templateRepository.GetAsync(input.Id);

            if (template == null)
            {
                throw new UserFriendlyException("Product Service Not Found!");
            }

            input.MapTo(template);

            await _templateRepository.UpdateAsync(template);
        }

        public async Task DeleteTemplate(EntityRequestInput<long> input)
        {
            var template = await _templateRepository.GetAsync(input.Id);

            if (template == null)
            {
                throw new UserFriendlyException("Template not found!");
            }

            await _templateRepository.DeleteAsync(template);

            await CurrentUnitOfWork.SaveChangesAsync();
        }

        public async Task<int> CreateTemplateStatus(TemplateStatusInput input)
        {
            var templatestatus = new TemplateStatus();
            
            input.MapTo(templatestatus);

            return await _templateStatusRepository.InsertAndGetIdAsync(templatestatus);

          
        }

        public async Task UpdateTemplateStatus(TemplateStatusInput input)
        {
            var templatestatus = await _templateStatusRepository.GetAsync(input.Id);

            if (templatestatus == null)
            {
                throw new UserFriendlyException("Template Status Not Found!");
            }

            input.MapTo(templatestatus);

            await _templateStatusRepository.UpdateAsync(templatestatus);
        }

        public async Task DeleteTemplateStatus(EntityRequestInput input)
        {
            var templatestatus = await _templateStatusRepository.GetAsync(input.Id);

            if (templatestatus == null)
            {
                throw new UserFriendlyException("Template Status not found!");
            }

            await _templateStatusRepository.DeleteAsync(templatestatus);

            CurrentUnitOfWork.SaveChanges();
        }       
        
        public async Task<TemplateOutput> GetTemplate(EntityRequestInput<long> input)
        {
            var template = await _templateRepository.GetAsync(input.Id);

            if (template == null)
            {
                throw new UserFriendlyException("Template not found!");
            }

            var result = new TemplateOutput();

            template.MapTo(result);

            return result;            
        } 

        public async Task<int> CreateTemplateCategory(TemplateCategoryInput input)
        {
            var templatecategory = new TemplateCategory();

            input.MapTo(templatecategory);

            return await _templateCategoryRepository.InsertAndGetIdAsync(templatecategory);
        }

        public async Task UpdateTemplateCategory(TemplateCategoryInput input)
        {
            var templatecategory = await _templateCategoryRepository.GetAsync(input.Id);

            if (templatecategory == null)
            {
                throw new UserFriendlyException("Template Category Not Found!");
            }

            input.MapTo(templatecategory);

            await _templateCategoryRepository.UpdateAsync(templatecategory);
        }

        public async Task DeleteTemplateCategory(EntityRequestInput input)
        {
            var templatecategory = await _templateCategoryRepository.GetAsync(input.Id);

            if (templatecategory == null)
            {
                throw new UserFriendlyException("Template Category not found!");
            }          

            await _templateCategoryRepository.DeleteAsync(templatecategory);

            await CurrentUnitOfWork.SaveChangesAsync();
        }


        public async Task<TemplateListOutput> GetTemplates(TemplateListInput input)
        {
            var results = await _templateRepository.GetAll().WhereIf(!input.SearchedName.IsNullOrEmpty(), p => p.Name.Contains(input.SearchedName)).OrderBy(x => x.Name)
                            .Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount).ToListAsync();



            return new TemplateListOutput { Templates = Mapper.Map<List<TemplateOutput>>(results) };
        }

        public async Task<TemplateStatusListOutput> GetTemplatesStatuses(TemplateStatusListInput input)
        {
            var results = await _templateStatusRepository.GetAll().WhereIf(!input.SearchedName.IsNullOrEmpty(), p => p.Name.Contains(input.SearchedName)).OrderBy(x=> x.Name)
                            .Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount).ToListAsync();



            return new TemplateStatusListOutput { TemplateStatuses = Mapper.Map<List<TemplateStatusOutput>>(results) };
        }

        public async Task<TemplateCategoryListOutput> GetTemplateCategories(TemplateCategoryListInput input)
        {
            var results = await _templateCategoryRepository.GetAll().WhereIf(!input.SearchedName.IsNullOrEmpty(), p => p.Category.Name.Contains(input.SearchedName)).WhereIf(!input.TemplateIdFilter.HasValue, y=> y.TemplateId == input.TemplateIdFilter.Value).OrderBy(x => x.Id)
                            .Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount).ToListAsync();



            return new TemplateCategoryListOutput { TemplateCategories = Mapper.Map<List<TemplateCategoryOutput>>(results) };
        }
    }

First off, I want to say this framework has saved me hours of development time and I have only been using this for 3 weeks. I have ran into a little issue and I hope you guys can help me out. Most of my application is going to be using the entity framework for database information, however, there is a module that we are building that will work with MongoDB or DocumentsDB to store all the session information. I want to build a custom repository but I am confused as to how to set this up do I need to add a class to the solution and reference the IRepository interface and fill in the concrete methods for accessing the information in the no sql database. Should I build a separate dll entirely?

Thanks!

Showing 11 to 13 of 13 entries