public async Task <ActionResult> DeleteRT(ViewModels.EditRT updateRT) { if (updateRT != null) { var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name) .SingleOrDefaultAsync(); if (currentUser != null) { var editRT = new Models.RT { IsDeleted = true, IsActive = false, DeletedBy = currentUser, Deleted = DateTimeOffset.UtcNow }; try { db.Entry(editRT).State = EntityState.Modified; var result = await db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("RT", "VillageHead")); } } catch (Exception ex) { Trace.TraceError(ex.Message); Trace.TraceError(ex.StackTrace); } } } return(View("Error")); }
public async Task <ActionResult> AddRT(ViewModels.AddRT newRT) { if (ModelState.IsValid) { var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name) .SingleOrDefaultAsync(); if (currentUser != null) { var addRT = new Models.RT { IdRT = newRT.IdRT, Name = newRT.Name, Chairman = newRT.Chairman, IsActive = true, CreatedBy = currentUser, Created = DateTimeOffset.UtcNow }; try { db.RT.Add(addRT); var result = await db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("RT", "VillageHead")); } } catch (Exception ex) { Trace.TraceError(ex.Message); Trace.TraceError(ex.StackTrace); } } } return(View("Error")); }