Ejemplo n.º 1
0
        public async Task <IActionResult> Create_Or_Update(Services inputModel)
        {
            try
            {
                if (string.IsNullOrEmpty(inputModel.Name))
                {
                    throw new Exception($"Tên {MessageConst.NOT_EMPTY_INPUT}");
                }
                if (inputModel.Id == 0)
                {
                    inputModel.CreatedDate = DateTime.Now;
                    await _servicesManager.Create(inputModel);

                    return(Json(new { Result = true, Message = "Thêm mới dữ liệu thành công" }));
                }
                else
                {
                    inputModel.UpdatedDate = DateTime.Now;
                    await _servicesManager.Update(inputModel);

                    return(Json(new { Result = true, Message = "Cập nhật dữ liệu thành công" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Message = ex.Message }));
            }
        }
Ejemplo n.º 2
0
 public ActionResult NewRating(ServicePageViewModel model)
 {
     try
     {
         var service = _servicesManager.GetById(model.Id);
         service.rating = (short)((service.rating + model.NewRating) / 2);
         _servicesManager.Update(service);
         return(RedirectToRoute("ServicePage", new { id = model.Id }));
     }
     catch (Exception)
     {
         return(RedirectToRoute("ServicePage", new { id = model.Id }));
     }
 }