public JsonResult Action(TimingActionModel model) { bool result; string msg = ""; JsonResult jsonResult = new JsonResult(); if (model.ID == 0) { Timing timing = new Timing { Day = model.Day, Number = model.Number, OpeningTime = model.OpeningTime, ClosingTime = model.ClosingTime, ModifiedOn = DateTime.Now, UserID = UserHelperInfo.GetUserId(), IP = UserInfo.IP(), Agent = UserInfo.Agent(), Location = UserInfo.Location() }; try { result = service.Save(timing); msg += "success"; } catch (DbEntityValidationException e) { result = false; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { msg += "" + string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } catch (Exception exc) { msg += exc.Message.ToString() + " Detail : " + exc.InnerException.ToString(); result = false; } jsonResult.Data = result ? (new { Success = result, Msg = msg }) : (new { Success = false, Msg = msg }); } else { Timing timing = new Timing { ID = model.ID, Day = model.Day, Number = model.Number, OpeningTime = model.OpeningTime, ClosingTime = model.ClosingTime, ModifiedOn = DateTime.Now, UserID = UserHelperInfo.GetUserId(), IP = UserInfo.IP(), Agent = UserInfo.Agent(), Location = UserInfo.Location() }; try { result = service.Update(timing); msg += "success"; } catch (DbEntityValidationException e) { result = false; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { msg += "" + string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } catch (Exception exc) { msg += exc.Message.ToString() + " Detail : " + exc.InnerException.ToString(); result = false; } jsonResult.Data = result ? (new { Success = result, Msg = msg }) : (new { Success = result, Msg = msg }); } return(jsonResult); }