Beispiel #1
0
        public ControllerMessage Update(CategoryEditDTO categoryEditDTO)
        {
            string message = String.Empty;
            bool   success = Validate(categoryEditDTO.NewName, ref message);

            if (success)
            {
                try
                {
                    CategoryEntity categoryEntity = unitOfWork.Categories.Get(categoryEditDTO.OldName);
                    categoryEntity.Name = categoryEditDTO.NewName;

                    unitOfWork.Commit();

                    message = "Category changed";
                }
                catch (Exception ex)
                {
                    success = false;
                    message = ExceptionMessageBuilder.BuildMessage(ex);
                }
            }

            return(new ControllerMessage(success, message));
        }
Beispiel #2
0
        public DataControllerMessage <CategoryEditDTO> Get(CategoryDisplayDTO categoryDisplayDTO)
        {
            string          message = String.Empty;
            bool            success = true;
            CategoryEditDTO data    = null;

            try
            {
                CategoryEntity categoryEntity = unitOfWork.Categories.Get(categoryDisplayDTO.Name);
                data = new CategoryEditDTO
                {
                    NewName = categoryEntity.Name,
                    OldName = categoryEntity.Name
                };

                foreach (DishEntity dishEntity in categoryEntity.Dishes)
                {
                    data.Dishes.Add(new DishDisplayDTO
                    {
                        CategoryName = categoryEntity.Name,
                        Name         = dishEntity.Name,
                        Price        = dishEntity.Price
                    });
                }
            }
            catch (Exception ex)
            {
                success = false;
                message = ExceptionMessageBuilder.BuildMessage(ex);
            }

            return(new DataControllerMessage <CategoryEditDTO>(success, message, data));
        }
Beispiel #3
0
 public static Categories Dto2CategoryEntity(this CategoryEditDTO token)
 {
     return(new Categories
     {
         CategoryName = token.name
         , IsActive = token.isActive
     });
 }
Beispiel #4
0
        private void RaiseCategoryDeleteRequestEvent(CategoryEditDTO category)
        {
            var handler = CategoryDeleteRequest;

            if (handler != null)
            {
                GenericEventArgs <CategoryEditDTO> e = new GenericEventArgs <CategoryEditDTO>(category);
                handler(this, e);
            }
        }
Beispiel #5
0
        public CategoryEditViewModel(CategoryEditDTO category)
        {
            this.category = category;

            this.SaveCommand = new DelegateCommand(
                () => RaiseCategorySaveRequestEvent(category),
                obj => CanSave());
            this.DeleteCommand = new DelegateCommand(() => RaiseCategoryDeleteRequestEvent(category));

            this.Dishes = new ObservableCollection <string>(category.Dishes.Select(d => d.Name));
        }
        public async Task <IActionResult> Update(int id, CategoryEditDTO categoryDTO)
        {
            if (id != categoryDTO.Id)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _categoryService.Update(_mapper.Map <Category>(categoryDTO));

            return(Ok(categoryDTO));
        }
Beispiel #7
0
        public ServiceMessage Edit(CategoryEditDTO categoryDTO)
        {
            int    id;
            string decryptedId = encryptor.Decrypt(categoryDTO.Id);

            List <string> errors    = new List <string>();
            bool          succeeded = true;

            if (Int32.TryParse(decryptedId, out id))
            {
                if (succeeded = Validate(categoryDTO.Name, errors))
                {
                    try
                    {
                        CategoryEntity categoryEntity = unitOfWork.Categories.Get(id);
                        if (categoryEntity != null)
                        {
                            categoryEntity.Name      = categoryDTO.Name;
                            categoryEntity.IsEnabled = categoryDTO.IsEnabled;

                            unitOfWork.Commit();
                        }
                        else
                        {
                            succeeded = false;
                            errors.Add("Such category was not found");
                        }
                    }
                    catch (Exception ex)
                    {
                        ExceptionMessageBuilder.FillErrors(ex, errors);
                        succeeded = false;
                    }
                }
            }
            else
            {
                succeeded = false;
                errors.Add("Such category was not found");
            }

            return(new ServiceMessage
            {
                Errors = errors,
                Succeeded = succeeded
            });
        }
Beispiel #8
0
        public ActionResult Edit(CategoryEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Id = HttpUtility.UrlDecode(model.Id);
                CategoryEditDTO categoryDTO    = Mapper.Map <CategoryEditViewModel, CategoryEditDTO>(model);
                ServiceMessage  serviceMessage = service.Edit(categoryDTO);
                if (serviceMessage.Succeeded)
                {
                    return(RedirectToAction("List"));
                }
                else
                {
                    AddModelErrors(serviceMessage.Errors);
                }
            }

            return(View(model));
        }
Beispiel #9
0
        public DataServiceMessage <CategoryEditDTO> Get(string categoryId)
        {
            int    id;
            string decryptedId = encryptor.Decrypt(categoryId);

            List <string>   errors    = new List <string>();
            bool            succeeded = true;
            CategoryEditDTO data      = null;

            if (Int32.TryParse(decryptedId, out id))
            {
                try
                {
                    CategoryEntity categoryEntity = unitOfWork.Categories.Get(id);
                    data = new CategoryEditDTO
                    {
                        Id        = categoryId,
                        Name      = categoryEntity.Name,
                        IsEnabled = categoryEntity.IsEnabled
                    };
                }
                catch (Exception ex)
                {
                    ExceptionMessageBuilder.FillErrors(ex, errors);
                    succeeded = false;
                }
            }
            else
            {
                succeeded = false;
                errors.Add("Such category was not found");
            }

            return(new DataServiceMessage <CategoryEditDTO>
            {
                Errors = errors,
                Succeeded = succeeded,
                Data = data
            });
        }
Beispiel #10
0
        private void DisplayCategory(CategoryEditDTO categoryEditDTO)
        {
            CategoryEditViewModel viewModel = new CategoryEditViewModel(categoryEditDTO);
            CategoryEditView      view      = new CategoryEditView(viewModel);
            Window window = WindowFactory.CreateByContentsSize(view);

            viewModel.CategorySaveRequest += (s, e) =>
            {
                using (ICategoryController controller = factory.CreateCategoryController())
                {
                    ControllerMessage controllerMessage = controller.Update(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };

            window.Show();
        }
Beispiel #11
0
        public ActionResult SaveCategory([DataSourceRequest] DataSourceRequest request, CategoryEditDTO category)
        {
            if (category != null && ModelState.IsValid)
            {
                string error;
                _categoryManageServices.SaveCategory(ref category, out error);
            }

            return(Json(new[] { category }.ToDataSourceResult(request, ModelState)));
        }
Beispiel #12
0
        public ActionResult DestroyCategory([DataSourceRequest] DataSourceRequest request, CategoryEditDTO category)
        {
            if (category != null)
            {
                string error;
                _categoryManageServices.DeleteCategory(category, out error);
            }

            return(Json(ModelState.ToDataSourceResult()));
        }
Beispiel #13
0
 public static void UpdateCategoryEntity(this Categories entity, CategoryEditDTO token)
 {
     entity.CategoryName = token.name;
     entity.IsActive     = token.isActive;
 }