public async Task <IActionResult> PostData(Modules Data) { if (!ModelState.IsValid) { return(Json(new { danger = TM.Common.Error.Model })); } if (DataNameExists(Data.AppKey)) { return(Json(new { danger = TM.Common.Error.Exist })); } try { //Data.Id = Guid.NewGuid(); Data.Action = "," + Data.Action + ","; Data.CreatedBy = Common.Auth.getUserAction(); Data.CreatedAt = DateTime.Now; Data.UpdatedBy = Common.Auth.getUserAction(); Data.UpdatedAt = DateTime.Now; _context.Modules.Add(Data); await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (DataExistsID(Data.Id)) { return(Json(new { danger = TM.Common.Error.IDExist })); } else { return(Json(new { danger = TM.Common.Error.DB })); } } return(Json(new { success = TM.Common.Success.Create })); }
public async Task <IActionResult> Create([Bind("Id,ModuleKey,SubKey,Value,SubValue,Desc,Orders,Flag,Extras")] Settings settings) { if (ModelState.IsValid) { //settings.Id = Guid.NewGuid(); _context.Add(settings); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(settings)); }
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 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> PostUsers(Users users) { if (!ModelState.IsValid) { return(Json(new { danger = TM.Common.Error.Model })); } if (UsersNameExists(users.Username)) { return(Json(new { danger = TM.Common.Error.Exist })); } try { users.Id = Guid.NewGuid(); users.Salt = Guid.NewGuid().ToString(); users.Password = TM.Encrypt.MD5.CryptoMD5TM(users.Password + users.Salt); users.Roles = ""; users.CreatedBy = Common.Auth.getUserAction(); users.CreatedAt = DateTime.Now; users.UpdatedBy = Common.Auth.getUserAction(); users.UpdatedAt = DateTime.Now; //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]; } _context.Users.Add(users); await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (UsersExistsID(users.Id)) { return(Json(new { danger = TM.Common.Error.IDExist })); } else { return(Json(new { danger = TM.Common.Error.DB })); } } return(Json(new { success = TM.Common.Success.Create })); }