public async Task <IActionResult> Update(Guid id, Users users)//[FromBody] { if (!ModelState.IsValid) { return(Json(new { danger = TM.Common.Error.Model })); } if (id != users.Id) { return(Json(new { danger = TM.Common.Error.Update })); } try { users.Roles = "," + users.Roles + ","; users.UpdatedBy = Common.Auth.getUserAction(); users.UpdatedAt = DateTime.Now; _context.Users.Attach(users); var entry = _context.Entry(users); entry.Property(m => m.FullName).IsModified = true; entry.Property(m => m.Mobile).IsModified = true; entry.Property(m => m.Email).IsModified = true; entry.Property(m => m.Address).IsModified = true; entry.Property(m => m.Details).IsModified = true; entry.Property(m => m.Orders).IsModified = true; entry.Property(m => m.Roles).IsModified = true; entry.Property(m => m.Flag).IsModified = true; entry.Property(m => m.UpdatedBy).IsModified = true; entry.Property(m => m.UpdatedAt).IsModified = true; //Create Directory Upload var upload = new TM.Helper.Upload(Request.Form.Files, TM.Common.Directories.Uploads + PathInUpload); var file = upload.ImagesName(); if (file.Count > 0) { users.Images = TM.Common.Directories.Uploads + PathInUpload + file[0]; entry.Property(m => m.Images).IsModified = true; } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Json(new { danger = TM.Common.Error.DB })); } return(Json(new { success = TM.Common.Success.Update })); }
public async Task <IActionResult> PutUsers(Users _users)//[FromBody] { if (!ModelState.IsValid) { return(Json(new { danger = TM.Common.Error.Model })); } try { _context.Users.Attach(_users); var entry = _context.Entry(_users); entry.Property(m => m.FullName).IsModified = true; entry.Property(m => m.Mobile).IsModified = true; entry.Property(m => m.Email).IsModified = true; entry.Property(m => m.Address).IsModified = true; entry.Property(m => m.Details).IsModified = true; entry.Property(m => m.Images).IsModified = true; await _context.SaveChangesAsync(); } catch (Exception) { return(Json(new { danger = TM.Common.Error.DB })); } return(Json(new { success = TM.Common.Success.Update })); }
public ActionResult Edit([Bind(Include = "id,moduleKey,subKey,value,subValue,desc,orders,flag,extras")] Setting setting) { if (ModelState.IsValid) { db.Entry(setting).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(setting)); }
public async Task <IActionResult> Update(Users users)//[FromBody] { if (!ModelState.IsValid) { return(Json(new { danger = TM.Common.Error.Model })); } if (users.Id != Common.Auth.AuthUser.Id && await _context.Users.SingleOrDefaultAsync(m => m.Id == Common.Auth.AuthUser.Id) == null) { return(Json(new { success = TM.Common.Success.Update })); } try { users.UpdatedBy = Common.Auth.getUserAction(); users.UpdatedAt = DateTime.Now; _context.Users.Attach(users); var entry = _context.Entry(users); entry.Property(m => m.FullName).IsModified = true; entry.Property(m => m.Mobile).IsModified = true; entry.Property(m => m.Email).IsModified = true; entry.Property(m => m.Address).IsModified = true; entry.Property(m => m.Details).IsModified = true; entry.Property(m => m.Images).IsModified = true; entry.Property(m => m.UpdatedBy).IsModified = true; entry.Property(m => m.UpdatedAt).IsModified = true; //Create Directory Upload var upload = new TM.Helper.Upload(Request.Form.Files, TM.Common.Directories.Uploads + PathInUpload); var file = upload.ImagesName(); if (file.Count > 0) { users.Images = TM.Common.Directories.Uploads + PathInUpload + file[0]; entry.Property(m => m.Images).IsModified = true; } await _context.SaveChangesAsync(); //Update Session User Common.Auth.SetAuth(await _context.Users.SingleOrDefaultAsync(m => m.Id == Common.Auth.AuthUser.Id)); } catch (Exception) { return(Json(new { danger = TM.Common.Error.DB })); } return(Json(new { success = TM.Common.Success.Update })); }
public async Task <IActionResult> PutData(long id, Modules Data)//[FromBody] { if (!ModelState.IsValid) { return(Json(new { danger = TM.Common.Error.Model })); } if (id != Data.Id) { return(Json(new { danger = TM.Common.Error.Update })); } try { Data.Action = "," + Data.Action + ","; Data.UpdatedBy = Common.Auth.getUserAction(); Data.UpdatedAt = DateTime.Now; _context.Modules.Attach(Data); var entry = _context.Entry(Data); entry.Property(m => m.Name).IsModified = true; entry.Property(m => m.Url).IsModified = true; entry.Property(m => m.Action).IsModified = true; entry.Property(m => m.Icon).IsModified = true; entry.Property(m => m.Orders).IsModified = true; entry.Property(m => m.Flag).IsModified = true; entry.Property(m => m.UpdatedBy).IsModified = true; entry.Property(m => m.UpdatedAt).IsModified = true; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Json(new { danger = TM.Common.Error.DB })); } return(Json(new { success = TM.Common.Success.Update })); }
public virtual void Add(T entity) { EntityEntry dbEntityEntry = _context.Entry <T>(entity); _context.Set <T>().Add(entity); }