public int UpdateMeal(MealUpdateModel model)
        {
            using (var context = new HallAutomationSystemEntities())
            {
                var meal = context.Meal.FirstOrDefault(x => x.MealId == model.MealId && x.Date == DateTime.Today);
                if (meal == null)
                {
                    return(-3);
                }
                TimeSpan now   = DateTime.Now.TimeOfDay;
                TimeSpan start = new TimeSpan(00, 0, 0);
                TimeSpan End   = new TimeSpan(24, 00, 0);
                if (!(now >= start && now <= End))
                {
                    return(-1);
                }

                int taka      = searchOperation.GetMealCost();
                int meal_cost = (meal.Dinnar * taka + meal.Lunch * taka);
                accountInformation.decreamentAccountBalance((int)meal.StudentId, (-1) * meal_cost);
                int     New_Meal_Cost = (model.Dinnar * taka + model.Lunch * taka);
                Account account       = searchOperation.GetAccount((int)meal.StudentId);
                if (New_Meal_Cost > account.Balance)
                {
                    return(-2);
                }
                meal.Lunch  = model.Lunch;
                meal.Dinnar = model.Dinnar;
                context.SaveChanges();
                return(meal.MealId);
            }
        }
        public ActionResult MealEdit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MealUpdateModel mealUpdateModel = new MealUpdateModel();

            mealUpdateModel.MealId = (int)id;
            return(View(mealUpdateModel));
        }
示例#3
0
        public async Task <ActionResult> Put([FromBody] MealUpdateModel model)
        {
            await _mealService.UpdateMealAsync(model);

            var response = new ResponseModel
            {
                Message = $"The meal has been updated"
            };

            return(Ok(response));
        }
 public ActionResult MealEdit(MealUpdateModel model)
 {
     if (ModelState.IsValid)
     {
         int id = mealInformation.UpdateMeal(model);
         if (id > 0)
         {
             ViewBag.Success = "Meal Updated!";
             ModelState.Clear();
         }
         else if (id == -1)
         {
             ViewBag.Success = "Time Is Over!";
         }
         else
         {
             ViewBag.Success = "Insufficient Balance!";
         }
     }
     return(View("MealDetails"));
 }
示例#5
0
        public async Task UpdateMealAsync(MealUpdateModel model)
        {
            if (model != null)
            {
                var entity = await _repository.GetAll <Meal>().FirstOrDefaultAsync(x => x.Id == model.Id);

                if (entity == null)
                {
                    throw new Exception("Meal entity is null on update operation!");
                }

                entity.Date             = model.Date;
                entity.Time             = model.Time;
                entity.NumberOfCalories = model.NumberOfCalories;
                entity.Description      = model.Description;

                _repository.Update(entity);

                await _repository.SaveAllAsync();
            }
        }