public JsonResult SendMessage(int?id, string answer) { VizewDbContext db = new VizewDbContext(); Contact contact = db.Contact.FirstOrDefault(p => p.Id == id); //if (contact == null) //{ // return HttpNotFound(); //} contact.IsAnswered = true; contact.AnsweredDate = DateTime.Now; contact.Answer = answer; db.SaveChanges(); return(Json(contact)); }
public ActionResult Contact(Contact contact) { if (!ModelState.IsValid) { ViewBag.Message = "Boş xanaları doldurun."; } else { ViewBag.Message = "Mesaj göndərildi."; using (VizewDbContext db = new VizewDbContext()) { db.Contact.Add(contact); db.SaveChanges(); } } return(View()); }
public void OnException(ExceptionContext filterContext) { var area = "";//todo.... var controller = (filterContext.RouteData.Values["controller"] ?? "").ToString(); var action = (filterContext.RouteData.Values["action"] ?? "").ToString(); //səbəbkar erroru tapmaq while (filterContext.Exception.InnerException != null) { filterContext.Exception = filterContext.Exception.InnerException; } var model = new HandleErrorInfo(filterContext.Exception, controller, action); try { using (var db = new VizewDbContext()) { var entity = new ErrorHistory(); if (!string.IsNullOrWhiteSpace(area)) { entity.AreaName = area; } if (!string.IsNullOrWhiteSpace(controller)) { entity.ControllerName = controller; } if (!string.IsNullOrWhiteSpace(action)) { entity.ActionName = action; } if (filterContext.Exception is HttpException) { entity.ErrorCode = (filterContext.Exception as HttpException).GetHttpCode(); } else if (filterContext.Exception is SqlException) { entity.ErrorCode = (filterContext.Exception as SqlException).Number; entity.ErrorMessage = filterContext.Exception.Message; } else { entity.ErrorMessage = filterContext.Exception.Message; } db.ErrorHistory.Add(entity); db.SaveChanges(); } } catch (Exception ex) { logger.Fatal(ex); } filterContext.Result = new ViewResult { ViewName = "~/Views/Shared/Error.cshtml", MasterName = "~/Views/Shared/_Layout.cshtml", ViewData = new ViewDataDictionary <HandleErrorInfo>(model), TempData = filterContext.Controller.TempData }; filterContext.ExceptionHandled = true; }