//[ValidateAntiForgeryToken] public ActionResult Edit(User model, string returnUrl = "") { if (!ModelState.IsValid) { return(View(model)); } if (model.Password != model.ConfirmPassword) { ModelState.AddModelError("", "The password and confirmation password do not match."); return(View(model)); } try { // Edit user into DB var entity = db.Users.Find(model.UserId); db.Entry(entity).CurrentValues.SetValues(model); db.SaveChanges(); TempData["Success"] = "User has been updated successfully!"; return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.MySqlExMessage()); return(View(model)); } }
public ActionResult DeleteUserVehicle(int id, int year, int month) { try { var entity = db.UsersVehicles.Find(id); db.Entry(entity).State = EntityState.Deleted; db.SaveChanges(); TempData["DeleteMessage"] = "Eliminato con Successo!"; } catch (Exception ex) { TempData["DeleteMessage"] = string.Format("[Errore] {0}", ex.MySqlExMessage()); } return(RedirectToAction("Index", new { year = year, month = month })); }
public ActionResult FreezeMonth(int year = 0, int month = 0) { try { var entity = db.MonthsFrozen.Find(year, month); if (entity == null) { // Aggiungo entity = new Models.MonthFrozen { Year = year, Month = month }; db.MonthsFrozen.Add(entity); TempData["AlertMessage"] = "Mese Bloccato con Successo"; } else { // Elimino db.Entry(entity).State = EntityState.Deleted; TempData["AlertMessage"] = "Mese Sbloccato con Successo"; } db.SaveChanges(); } catch (Exception ex) { TempData["AlertMessage"] = string.Format("Error: {0}", ex.MySqlExMessage()); } return(RedirectToAction("ReportUsers", new { year = year, month = month })); }
public ActionResult DeleteHoliday(int id, int year) { try { var entity = db.Holidays.Find(id); if (entity.Status == Status_Request.Approvata) { throw new Exception("Impossibile Eliminare Ferie Approvate"); } db.Entry(entity).State = EntityState.Deleted; db.SaveChanges(); TempData["DeleteMessage"] = "Annullata con Successo!"; } catch (Exception ex) { TempData["DeleteMessage"] = string.Format("[Errore] {0}", ex.MySqlExMessage()); } return(RedirectToAction("Index", new { year = year })); }
public ActionResult Edit(Order model) { if (!ModelState.IsValid) { return(View(model)); } try { var entity = db.Orders.Find(model.OrderId); db.Entry(entity).CurrentValues.SetValues(model); db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("", ex.MySqlExMessage()); return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult DeleteHour(long DateTicks = 0, string UserId = null) { UserId = (UserId == null) ? User.Identity.Name : UserId; var date = new DateTime(DateTicks); try { // Verifico gli ordini di quel giorno che per quel giorno if (db.WorkOrders.Where(x => x.UserId == UserId && DbFunctions.TruncateTime(x.Date) == DbFunctions.TruncateTime(date)).Count() > 0) { throw new Exception("Impossibile Eliminare Giorni con commesse associate"); } // Delete user into DB var entity = db.Hours.Find(UserId, date); db.Entry(entity).State = EntityState.Deleted; db.SaveChanges(); TempData["Error"] = "Giorno Eliminato con Successo!"; } catch (Exception ex) { TempData["Error"] = ex.MySqlExMessage(); } return(RedirectToAction("Index", new { year = date.Year, month = date.Month })); }
public ActionResult DeleteMaterial(int Id, string returnUrl = "") { try { var entity = db.Materials.Find(Id); db.Entry(entity).State = EntityState.Deleted; db.SaveChanges(); TempData["DeleteMessage"] = "Eliminato con Successo!"; } catch (Exception ex) { TempData["DeleteMessage"] = string.Format("[Errore] {0}", ex.MySqlExMessage()); } return(Redirect(returnUrl)); }