Ejemplo n.º 1
0
        ActionOutput IDishManager.AddDish(AddDishModel model)
        {
            ActionOutput res = new ActionOutput();

            try
            {
                var already = Context.Dishes.Where(p => p.Name == model.Name).Any();
                if (!already)
                {
                    Dish _dish = new Dish();
                    _dish.CategoryId  = model.CategoryId;
                    _dish.Description = model.Description;
                    _dish.IsDeleted   = false;
                    _dish.Name        = model.Name;
                    _dish.CreatedDate = DateTime.Now;
                    Context.Dishes.Add(_dish);
                    Context.SaveChanges();
                    res.Status  = ActionStatus.Successfull;
                    res.Message = "Dish Added Successfully";
                }
                else
                {
                    res.Status  = ActionStatus.Error;
                    res.Message = "Dish with the same name already exists.";
                }
            }
            catch (Exception ex)
            {
                res.Status  = ActionStatus.Error;
                res.Message = "Some Error Occurred";
            }
            return(res);
        }
        public ErrorModel AddDishToMenu(AddDishModel model)
        {
            var errors = new ErrorModel();

            if (model == null)
            {
                errors.Messages.Add("Invalid data.");
                return(errors);
            }

            var dish = model.DishToAdd;

            if (dish == null)
            {
                errors.Messages.Add("No dish found to add.");
                return(errors);
            }

            var provider = DbContext.GetProviders().SingleOrDefault(p => p.ProviderId == model.ProviderId);

            if (provider == null || provider.ProviderStatus != ProviderStatus.Verified)
            {
                errors.Messages.Add("Cannot add dish for any address not verified provider.");
                return(errors);
            }

            var newDish = dish.ToEntity();

            newDish.ProviderId = model.ProviderId;
            newDish.Available  = true;

            try
            {
                DbContext.SaveDishes(new List <DishEntity> {
                    newDish
                });
                return(errors);
            }
            catch (Exception ex)
            {
                errors.Messages.Add(ex.Message);
                return(errors);
            }
        }
 public ErrorModel AddDishToMenu(AddDishModel addModel)
 {
     return(Service.AddDishToMenu(addModel));
 }
Ejemplo n.º 4
0
 public JsonResult AddDish(AddDishModel model)
 {
     ViewBag.SelectedTab = SelectedAdminTab.Dish;
     return(JsonResult(_DishManager.AddDish(model)));
 }