public ActionResult ApprovalRole(string StoreId, string id) { var emp = GetDetailEmployee(StoreId, id); UserRoleModels model = new UserRoleModels(); model.EmployeeID = emp.ID; model.EmployeeEmail = emp.Email; model.EmployeeName = emp.Name; model.StoreName = emp.StoreName; var lstRole = GetSelectListRoles(StoreId); foreach (var item in lstRole) { model.ListRole.Add(new RoleItem { RoleId = item.Value, RoleName = item.Text }); } //====== var listROEmp = _UserRoleFactory.GetDataEmployee(id); model.ListRole.ForEach(x => { var UR = listROEmp.Where(z => z.RoleID.Equals(x.RoleId)).FirstOrDefault(); x.Checked = UR == null ? false : UR.IsActive; x.Id = UR == null ? "" : UR.Id; }); model.ListRole = model.ListRole.OrderByDescending(x => x.Checked).ToList(); return(PartialView("_ApprovalRole", model)); }
public IHttpActionResult EditFormData(int id, [FromBody] UserRoleModels.Edit userRole) { JavaScriptSerializer js = new JavaScriptSerializer(); string logForm = "Form : " + js.Serialize(userRole); string logAPI = "[Put] " + Request.RequestUri.ToString(); if (!ModelState.IsValid || userRole == null) { Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm); return(BadRequest("Invalid data")); } try { UserRoleModels userRoleModel = new UserRoleModels(); userRoleModel.updateUserRole(id, userRole); return(Ok("Success")); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); logMessage.AppendLine(logForm); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
public IHttpActionResult GetCompanyById(int id) { UserRoleModels userRoleModel = new UserRoleModels(); try { UserRoleModels.Detail company = userRoleModel.getUserRoleById(id); return(Ok(company)); } catch { return(NotFound()); } }
public async Task <ActionResult> Edit([Bind(Include = "Id,FullName,UserName,Email,RoleId,Identification,DOB,Height,Weight,Phone1,Phone2,Address1,Address2,Notes")] UserViewModel userModels) { if (ModelState.IsValid) { var user = new UserModels() { Id = userModels.Id, FullName = userModels.FullName, Email = userModels.Email, Identification = userModels.Identification, DOB = userModels.DOB, Height = userModels.Height, Weight = userModels.Weight, Phone1 = userModels.Phone1, Phone2 = userModels.Phone2, Address1 = userModels.Address1, Address2 = userModels.Address2, Notes = userModels.Notes }; var userRole = new UserRoleModels() { UserId = userModels.Id, RoleId = userModels.RoleId }; using (var database = new HrContext()) { database.User.Attach(user); database.Entry(user).Property(x => x.FullName).IsModified = true; database.Entry(user).Property(x => x.Email).IsModified = true; database.Entry(user).Property(x => x.Identification).IsModified = true; database.Entry(user).Property(x => x.DOB).IsModified = true; database.Entry(user).Property(x => x.Height).IsModified = true; database.Entry(user).Property(x => x.Weight).IsModified = true; database.Entry(user).Property(x => x.Phone1).IsModified = true; database.Entry(user).Property(x => x.Phone2).IsModified = true; database.Entry(user).Property(x => x.Address1).IsModified = true; database.Entry(user).Property(x => x.Address2).IsModified = true; database.Entry(user).Property(x => x.Notes).IsModified = true; database.UserRole.Attach(userRole); database.Entry(userRole).Property(x => x.RoleId).IsModified = true; await database.SaveChangesAsync(); } return(RedirectToAction("Index")); } ViewBag.listRole = new SelectList(db.Role.OrderBy(x => x.Name).ToList(), "Id", "Name"); return(View(userModels)); }
public IHttpActionResult Delete(int id) { try { UserRoleModels userRoleModel = new UserRoleModels(); userRoleModel.deleteUserRole(id); return(Ok("Success")); } catch (Exception ex) { string logAPI = "[Delete] " + Request.RequestUri.ToString(); StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError()); } }
public ActionResult ApprovalRole(UserRoleModels model) { try { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_ApprovalRole", model)); } List <UserRoleModels> listModel = new List <UserRoleModels>(); foreach (var item in model.ListRole) { listModel.Add(new UserRoleModels { Id = item == null ? "" : item.Id, RoleID = item.RoleId, EmployeeID = model.EmployeeID, IsActive = item.Checked, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, CreatedUser = CurrentUser.UserName, ModifiedUser = CurrentUser.UserName, }); } string msg = ""; bool result = _UserRoleFactory.InsertOrUpdate(listModel, ref msg); if (result) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("ListRole", msg); return(PartialView("_ApprovalRole", model)); } } catch (Exception ex) { _logger.Error("Approval_Role: " + ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public bool Insert(UserRoleModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { G_UserRole item = new G_UserRole(); item.Id = Guid.NewGuid().ToString(); item.RoleID = model.RoleID; item.EmployeeID = model.EmployeeID; item.IsActive = model.IsActive; //====== item.CreatedDate = DateTime.Now; item.CreatedUser = model.CreatedUser; item.ModifiedDate = DateTime.Now; item.ModifiedUser = model.ModifiedUser; cxt.G_UserRole.Add(item); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }