public ApiSimpleResult<UserRoleModel> DeleteUserRole(UserRoleModel userRole)
 {
     var response = AccountSvc.DeleteUserRole(userRole);
     return response;
 }
        public ApiSimpleResult<UserRoleModel> SaveUserRole(UserRoleModel userRole)
        {
            var result = new ApiSimpleResult<UserRoleModel>();
            var response = AccountSvc.SaveUserRole(userRole);
            if (response != null)
            {
                result.Data = response;
            }

            return result;
        }
 public ApiSimpleResult<UserRole> AddUserRole(UserRoleModel userRole)
 {
     var response = AccountSvc.CreateUserRole(userRole);
     ApiSimpleResult<UserRole> result = new ApiSimpleResult<UserRole>
     {
         StatusString = "Successful",
         Message = "Create new successfully",
         Data = response.Data
     };
     return result;
 }
 public ApiSimpleResult<UserRoleModel> DeleteUserRole(UserRoleModel userRole)
 {
     var status = db.GeneralStatuses.Find(userRole.GeneralStatus.StatusId);
     db.Entry(status).State = EntityState.Deleted;
     var updateUserRole = db.UserRoles.Find(userRole.UserRoleId);
     db.Entry(updateUserRole).State = EntityState.Deleted;
     ApiSimpleResult<UserRoleModel> result = new ApiSimpleResult<UserRoleModel>();
     try
     {
         db.SaveChanges();
         result.StatusString = "Successful";
         result.Message = "Delete data successfully";
         result.Data = userRole;
     }
     catch (DbUpdateConcurrencyException ex)
     {
         result.Message = "Error";
         result.StatusString = "Error";
     }
     return result;
 }
 public UserRoleModel SaveUserRole(UserRoleModel userRole)
 {
     var result = new UserRoleModel();
     var status = db.GeneralStatuses.Find(userRole.GeneralStatus.StatusId);
     status.UpdateTime = DateTime.Now;
     status.StatusName = userRole.Status;
     db.Entry(status).State = EntityState.Modified;
     var updateUserRole = db.UserRoles.Find(userRole.UserRoleId);
     updateUserRole.RoleId = userRole.RoleId;
     updateUserRole.UserId = userRole.UserId;
     updateUserRole.Note = userRole.Note;
     db.Entry(updateUserRole).State = EntityState.Modified;
     try
     {
         db.SaveChanges();
         result.UserRoleId = userRole.UserRoleId;
     }
     catch (DbUpdateConcurrencyException ex)
     {
         return null;
     }
     return result;
 }
 public UserRoleModel GetUserRoleDetail(int userRoleId)
 {
     UserRoleModel result = new UserRoleModel();
     var userRoles = db.UserRoles.Where(r => r.UserRoleId == userRoleId);
     if (userRoles.Any())
     {
         var userRole = userRoles.First();
         result.UserRoleId = userRole.UserRoleId;
         result.RoleId = userRole.RoleId;
         result.RoleName = userRole.Role.RoleName;
         result.Note = userRole.Note;
         result.UserId = userRole.UserId;
         result.UserName = userRole.User.UserName;
         result.Status = userRole.Status.StatusName;
         result.GeneralStatus = userRole.Status;
     }
     return result;
 }
 public ApiSimpleResult<UserRole> CreateUserRole(UserRoleModel userRole)
 {
     var result = new ApiSimpleResult<UserRole>() { StatusString = "Fail", Message = "Cannot create user role." };
     if (userRole != null)
     {
         var status = new GeneralStatus
         {
             StatusName = userRole.Status,
             CreateTime = DateTime.Now,
             UpdateTime = DateTime.Now
         };
         db.GeneralStatuses.Add(status);
         var newUserRole = new UserRole
         {
             RoleId = userRole.RoleId,
             UserId = userRole.UserId,
             Note = userRole.Note,
             StatusId = status.StatusId
         };
         db.UserRoles.Add(newUserRole);
         db.SaveChanges();
         result.StatusString = "Succesful";
         result.Message = "Create new UserRole successfully";
         result.Data = newUserRole;
     }
     return result;
 }