public Operation<AmountPriceModel> CreateAmountPrice(AmountPriceModel model)
        {
            return Operation.Create(() =>
            {
                try
                {
                    //model.Validate();
                    var isExists = _context.AmountPrices.Where(c => c.CreatedBy == model.CreatedBy).FirstOrDefault();
                    //if (isExists != null) throw new Exception("You cant vote twice");


                }

                catch( Exception ex)
                {
                    throw ex;
                }
                var entity = model.Create(model);
    
                _context.AmountPrices.Add(entity);

                _context.SaveChanges();


                return model;

                
            });
        }
        public ActionResult CreateAmountPrice(AmountPriceModel model)
        {
            model.CreatedBy = User.Identity.GetUserName();
            var result = _restMgr.CreateAmountPrice(model);

            if (result.Succeeded == true)
            {
                TempData["message"] = " was successfully added!";
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public ActionResult CreateRating(RatingExtensionModel model)
        {// RatingExtensionModel is a viewMoDEL that was use to pass the list of restaurants
            // voters was pass but was not used
            ViewBag.voters      = new SelectList(_votMgr.GetVoters().Result, "VoterId", "StaffName");
            ViewBag.restaurants = _restMgr.GetRestaurants().Result.ToList();

            var ratingModel = new Operation <RatingModel>();

            // var ratingModel = new List<RatingModel>();//do this u re not using Operation class

            if (ModelState.IsValid)
            {
                try
                {
                    bool   result  = false;
                    string staffId = User.Identity.GetUserName();

                    foreach (var item in model.ListRating)
                    {
                        ////to get the userId that login
                        item.CreatedBy = staffId;
                        RatingModel ratungmodel = new RatingModel
                        {
                            Quantity         = item.Quantity,
                            Quality          = item.Quality,
                            Taste            = item.Taste,
                            TimeLiness       = item.TimeLiness,
                            CustomerServices = item.CustomerServices,
                            CreatedBy        = item.CreatedBy,
                            RestId           = item.RestId
                        };
                        result = _ratMgr.CreateRating(ratungmodel);
                        ratingModel.Succeeded = true;
                    }
                    if (result)
                    {
                        // here i save the other two questions into another table
                        var amountPrice = new AmountPriceModel
                        {
                            CreatedBy         = staffId,
                            IsMfongComingBack = model.IsMfongComingBack,
                            AmountPriceId     = model.IsCatererSelected.ToString(),
                            CreatedDate       = DateTime.Now
                        };
                        // here i save the other two questions into another table
                        var amount = _restMgr.CreateAmountPrice(amountPrice);
                        {
                            if (amount.Succeeded)
                            {
                                TempData["message"] = $"    Your{""} voting was successfully added!";
                            }
                            //else
                            //{
                            //    throw new Exception("Please checked the button before submit");
                            //}
                        }
                    }


                    if (ratingModel.Succeeded == true)
                    {
                        //var results = _restMgr.GetRestaurants().Result.Where(x => x.IsChecked == true);
                        //return Content(String.Join(",", results.Select(x => x.RestId)));

                        TempData["message"] = $"    Your{""} voting was successfully added!";
                        if (User.IsInRole("Admin"))
                        {
                            return(RedirectToAction("Index"));
                        }

                        return(RedirectToAction("Index", "Home"));
                    }
                }
                //since model is a list, used foreach

                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }

            return(View(model));
        }