Beispiel #1
0
        public ActionResult CreateRating(List <RatingModel> model)
        {
            // voters was pass but was not used
            ViewBag.voters      = new SelectList(_votMgr.GetVoters().Result, "VoterId", "StaffName");
            ViewBag.restaurants = _restMgr.GetRestaurants().Result;

            var ratingModel = new Operation <RatingModel>();

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

            if (ModelState.IsValid)
            {
                //since model is a list, used foreach
                foreach (var item in model)
                {
                    ////to get the userId that login
                    item.CreatedBy = User.Identity.GetUserName();
                    var result = _ratMgr.CreateRating(item);
                    ratingModel.Succeeded = true;
                }

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

                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(model));
        }
        public ActionResult CreateRating(RatingModel[] model)
        {
            ViewBag.voters      = new SelectList(_votMgr.GetVoters().Result, "VoterId", "VotName");
            ViewBag.restaurants = new SelectList(_restMgr.GetRestaurants().Result, "RestId", "RestName");

            model.CreatedBy = User.Identity.GetUserId();
            var result = _ratMgr.CreateRating(model);

            if (result.Succeeded == true)
            {
                TempData["message"] = $"Rating{model.RatId} was successfully added!";

                if (User.IsInRole("Admin"))
                {
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index", "Home"));
            }
            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));
        }