public async Task <ActionResult> EditRW(ViewModels.AddRW updateRW) { if (updateRW != null) { var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name) .SingleOrDefaultAsync(); if (currentUser != null) { var editRW = new Models.RW { IdRW = updateRW.IdRW, Name = updateRW.Name, Chairman = updateRW.Chairman, IsActive = true, UpdatedBy = currentUser, Updated = DateTimeOffset.UtcNow }; try { db.Entry(editRW).State = EntityState.Modified; var result = await db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("RW", "VillageHead")); } } catch (Exception ex) { Trace.TraceError(ex.Message); Trace.TraceError(ex.StackTrace); } } } return(View("Error")); }
public async Task <ActionResult> AddRW(ViewModels.AddRW newRW) { if (ModelState.IsValid) { var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name) .SingleOrDefaultAsync(); if (currentUser != null) { var addRW = new Models.RW { IdRW = newRW.IdRW, Name = newRW.Name, Chairman = newRW.Chairman, IsActive = true, CreatedBy = currentUser, Created = DateTimeOffset.UtcNow }; try { db.RW.Add(addRW); var result = await db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("RW")); } } catch (Exception ex) { Trace.TraceError(ex.Message); Trace.TraceError(ex.StackTrace); } } } return(View("Error")); }