public ActionResult Create([Bind(Include = "Id,Name,DeletedDate,CreatedDate,UpdateDate")] Categories categories) { if (ModelState.IsValid) { db.Categories.Add(categories); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categories)); }
public ActionResult Create([Bind(Include = "Id,Email,Content,Subject,Answer,Name,IsReady")] Contact contact) { if (ModelState.IsValid) { db.Contact.Add(contact); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult PersonDetailsPost(PersonDetails personDetails, HttpPostedFileBase mediaUrl) { if (db.PersonDetails.Any()) { var person = db.PersonDetails.FirstOrDefault(); person.Age = personDetails.Age; person.Name = personDetails.Name; person.Phone = personDetails.Phone; person.MediaUrl = personDetails.MediaUrl; person.Location = personDetails.Location; person.Fax = personDetails.Fax; person.Email = personDetails.Email; person.Degree = personDetails.Degree; person.CareerLevel = personDetails.CareerLevel; person.Experience = personDetails.Experience; person.Website = personDetails.Website; person.UpdateDate = DateTime.Now; string i = mediaUrl.SaveImage(Server.MapPath("~/Template/Media")); person.MediaUrl = i; } if (ModelState.IsValid) { personDetails.CreatedDate = DateTime.Now; db.PersonDetails.Add(personDetails); db.SaveChanges(); } return(RedirectToAction("EditResumeAdmin")); }
public void DeleteImage(int carDetailImageId) { CarDetailPhotos carDetail = _context.CarDetailPhotos.Where(cd => cd.Id == carDetailImageId).FirstOrDefault(); Car car = _context.Cars.Where(c => c.Id == carDetail.CarId).Include(c => c.CarDetailPhotos).FirstOrDefault(); var carId = carDetail.CarId; _context.CarDetailPhotos.Remove(carDetail); _context.SaveChanges(); }
public ActionResult Contact(Contact emailModel) { if (emailModel.Name == null || emailModel.Email == null || emailModel.Content == null) { TempData["fill"] = "Name,Email,and Body must be written"; return(RedirectToAction("Contact")); } if (ModelState.IsValid) { db.Contact.Add(emailModel); db.SaveChanges(); Extension.SendMail(emailModel.Subject, emailModel.Content, emailModel.Email); return(RedirectToAction("Contact")); } return(RedirectToAction("Contact")); }
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 AspFinalDbContext()) { 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; } logger.Fatal(entity.ErrorMessage); entity.CreatedDate = DateTime.Now; db.ErrorHistories.Add(entity); db.SaveChanges(); } } catch (Exception) { //logger.Fatal(ex) } filterContext.Result = new ViewResult { ViewName = "~/Views/Home/ErrorHistory.cshtml", //MasterName = "~/Views/Shared/_Layout.cshtml", ViewData = new ViewDataDictionary <HandleErrorInfo>(model), TempData = filterContext.Controller.TempData }; filterContext.ExceptionHandled = true; }