public static UseFullCategory Map(UseFullCategory modelToUpdate, UseFullUpdatePostInputDtoModel dtoModel)
        {
            modelToUpdate.ImageAddress = dtoModel.ImageAddress;
            modelToUpdate.Name         = dtoModel.UseFullCategoryName;

            return(modelToUpdate);
        }
        public static UseFullUpdatePostInputDtoModel Map(UseFullUpdatePostInputViewModel viewModel)
        {
            if (viewModel.ImageAddress == null || viewModel.ImageAddress == "")
            {
                viewModel.ImageAddress = "/Images/No picture.jpg";
            }

            var dtoModel = new UseFullUpdatePostInputDtoModel
            {
                UseFullCategoryId   = viewModel.UseFullCategoryId,
                UseFullCategoryName = viewModel.UseFullCategoryName,
                ImageAddress        = viewModel.ImageAddress
            };

            return(dtoModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// change usefullcategory and add changes to database
        /// </summary>
        /// <param name="dtoModel"></param>
        /// <returns></returns>
        public async Task <bool> UpdateUseFullCategoryAsync(UseFullUpdatePostInputDtoModel dtoModel)
        {
            var allmodels = await this.useFullCategories.All().ToListAsync();

            if (allmodels.Any(x => x.ImageAddress == dtoModel.ImageAddress &&
                              x.Name == dtoModel.UseFullCategoryName))
            {
                return(true);
            }

            var modelToUpdate = allmodels.FirstOrDefault(x => x.Id == dtoModel.UseFullCategoryId);

            modelToUpdate = UseFullUpdatePostIputServiceMapper.Map(modelToUpdate, dtoModel);

            this.useFullCategories.Update(modelToUpdate);
            await this.useFullCategories.SaveAsync();

            return(false);
        }