コード例 #1
0
ファイル: RoleCustomController.cs プロジェクト: Debadatt/LGSE
 public IHttpActionResult AssignUnAssignUsersToRole(UsersToRoleRequest requestList)
 {
     try
     {
         string currentUserEmail = HttpUtilities.GetUserNameFromToken(this.Request);
         ValidationUtilities.ValidateAssignUnAssignUsersToRole(requestList);
         //Get Existing users of the role
         List <UserRoleMap> dbexistingUsers = context.UserRoleMaps.Where(i => i.RoleId == requestList.RoleId && i.Deleted == false).ToList();
         foreach (var item in requestList.UserIds)
         {
             if (dbexistingUsers.FirstOrDefault(i => i.UserId == item && i.RoleId == requestList.RoleId) == null)
             {
                 // if does not exists then only add it.
                 context.UserRoleMaps.Add(new UserRoleMap()
                 {
                     Id        = Guid.NewGuid().ToString(),
                     RoleId    = requestList.RoleId,
                     UserId    = item,
                     CreatedBy = currentUserEmail
                 });
             }
         }
         //remove existing mapping if they dont exists in the input
         foreach (var itemUser in dbexistingUsers)
         {
             if (requestList != null && requestList.UserIds != null)
             {
                 if (!requestList.UserIds.Contains(itemUser.UserId))
                 {
                     itemUser.Deleted = true;
                     context.Entry(itemUser).State = System.Data.Entity.EntityState.Modified;
                 }
             }
         }
         context.SaveChanges();
         return(Ok());
     }
     catch (HttpResponseException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         HttpUtilities.ServerError(ex, Request);
         return(null);
     }
 }
コード例 #2
0
 public IHttpActionResult ChangePassword(ChangePasswordRequest request)
 {
     try
     {
         //get user details from request _context
         User account = GetLoggedInUser();
         if (account != null)
         {
             //compare old password with the one saved in Db
             if (IsPasswordCorrect(request.OldPassword))
             {
                 if (IsPasswordCorrect(request.NewPassword))
                 {
                     return(BadRequest(ErrorCodes.PASSWORD_ALREADY_USED.ToString()));
                 }
                 byte[] pwdhash = AuthorizationUtilities.hash(request.NewPassword, account.Salt);
                 //     account.UpdatedAt = DateTime.UtcNow;
                 account.ModifiedBy   = account.Email;
                 account.Password     = pwdhash;
                 account.PwdStartDate = DateTimeOffset.UtcNow;
                 // _context.Entry(account).State = System.Data.Entity.EntityState.Modified;
                 _context.SaveChanges();
                 return(Ok(HttpUtilities.CustomResp(ErrorCodes.PWD_CHANGED.ToString())));
             }
             else
             {
                 return(BadRequest(ErrorCodes.OLD_PWD_NOTMATCHED.ToString()));
             }
         }
         else
         {
             return(BadRequest(ErrorCodes.INVALID_USER.ToString()));
         }
         //return Ok();
     }
     catch (Exception ex)
     {
         //Services.Log.Error(ex);
         LGSELogger.Error(ex);
         return(InternalServerError(ex));
     }
 }
コード例 #3
0
        // POST tables/PropertyUserStatus
        //public async Task<IHttpActionResult> PostPropertyUserStatus(PropertyUserStatus item)
        //{
        //    try
        //    {
        //        User account = GetLoggedInUser();
        //        //  item.RoleId = DbUtilities.GetUserPreferredRole(account.Email).Id;
        //        string userRole = HttpUtilities.GetUserRoleAccessApi(this.Request); // Added 24-10-2018
        //        var preferredRole = context.Roles.FirstOrDefault(i => i.Id == userRole); // Added 24-10-2018
        //        item.RoleId = preferredRole.Id;
        //        //Mapper.Initialize(cfg => cfg.CreateMap<PropertyUserStatusRequest, PropertyUserStatus>()
        //        //.ForMember(i => i.CreatedBy,j => j.UseValue(account.Email)).ForMember(i=>i.StatusChangedOn,j=>j.UseValue(DateTime.Now))
        //        //.ForMember(i => i.UserId, j => j.UseValue(account.Id))
        //        //);
        //        //var PropertyUserStatusMap = Mapper.Map<PropertyUserStatusRequest, PropertyUserStatus>(item);
        //        item.StatusChangedOn = DateTime.UtcNow;
        //        var propUserMap = context.PropertyUserMap.OrderByDescending(i => i.CreatedAt).FirstOrDefault(i => i.UserId == account.Id && i.PropertyId == item.PropertyId && i.RoleId == item.RoleId);
        //        if (propUserMap != null)
        //        {
        //            item.PropertyUserMapsId = propUserMap.Id;
        //        }
        //        item.CreatedBy = account.Email;
        //        PropertyUserStatus current = await InsertAsync(item);
        //        CreatedAtRoute("Tables", new { id = current.Id }, current);
        //        var IsIsaolated = context.PropertyStatusMstr.Where(i => i.Id == item.StatusId).Select(i => i.Status).FirstOrDefault();
        //        if (IsIsaolated == "Isolated")
        //        {
        //            var prop = context.Properties.Where(i => i.Id == item.PropertyId).ToList();
        //            if (prop != null && prop.Count > 0)
        //            {

        //                foreach (var propItem in prop)
        //                {
        //                    propItem.StatusId = item.StatusId;
        //                    propItem.SubStatusId = item.PropertySubStatusMstrsId;
        //                    propItem.IsIsolated = true;
        //                    propItem.UpdatedAt = DateTimeOffset.UtcNow;
        //                    propItem.ModifiedBy = account.Email;
        //                }

        //            }
        //            //context.SaveChanges();
        //        }
        //        else
        //        {
        //            var prop = context.Properties.Where(i => i.Id == item.PropertyId).ToList();
        //            if (prop != null && prop.Count > 0)
        //            {

        //                foreach (var propItem in prop)
        //                {
        //                    propItem.StatusId = item.StatusId;
        //                    propItem.SubStatusId = item.PropertySubStatusMstrsId;
        //                    propItem.UpdatedAt = DateTimeOffset.UtcNow;
        //                    propItem.ModifiedBy = account.Email;
        //                }

        //            }

        //        }
        //        context.SaveChanges();
        //        //var IncidentId = context.Properties.FirstOrDefault(i => i.Id == item.PropertyId).IncidentId;
        //        //DbUtilities.PropertyStatusCount(IncidentId);
        //        return Ok();
        //    }
        //    catch (Exception ex)
        //    {
        //        HttpUtilities.ServerError(ex, Request);
        //        return null;
        //    }

        //}
        public async Task <IHttpActionResult> PostPropertyUserStatus(PropertyUserStatus item)
        {
            try
            {
                User account = GetLoggedInUser();
                //  item.RoleId = DbUtilities.GetUserPreferredRole(account.Email).Id;
                string userRole      = HttpUtilities.GetUserRoleAccessApi(this.Request);    // Added 24-10-2018
                var    preferredRole = context.Roles.FirstOrDefault(i => i.Id == userRole); // Added 24-10-2018
                item.RoleId = preferredRole.Id;

                //var pusResult = context.PropertyUserStatus.Where(i => i.PropertyId == item.PropertyId && i.UserId == item.UserId && i.RoleId == item.RoleId && i.StatusId == null && i.Notes == null && i.Deleted == false).ToList();
                var pusResult = context.PropertyUserStatus.Where(i => i.Id == item.PropertyUserMapsId).ToList();

                if (pusResult != null && pusResult.Count > 0)
                {
                    foreach (var pusItem in pusResult)
                    {
                        pusItem.StatusId = item.StatusId;
                        pusItem.PropertySubStatusMstrsId = item.PropertySubStatusMstrsId;
                        pusItem.Notes           = item.Notes;
                        pusItem.StatusChangedOn = item.StatusChangedOn;
                        pusItem.ModifiedBy      = account.Email;
                    }


                    var prop = context.Properties.Where(i => i.Id == item.PropertyId).ToList();
                    if (prop != null && prop.Count > 0)
                    {
                        var IsIsaolated = context.PropertyStatusMstr.Where(i => i.Id == item.StatusId).Select(i => i.Status).FirstOrDefault();
                        if (IsIsaolated == "Isolated")
                        {
                            foreach (var propItem in prop)
                            {
                                propItem.StatusId    = item.StatusId;
                                propItem.SubStatusId = item.PropertySubStatusMstrsId;
                                propItem.IsIsolated  = true;
                                propItem.UpdatedAt   = DateTimeOffset.UtcNow;
                                propItem.ModifiedBy  = account.Email;
                            }
                        }
                        else
                        {
                            foreach (var propItem in prop)
                            {
                                propItem.StatusId    = item.StatusId;
                                propItem.SubStatusId = item.PropertySubStatusMstrsId;
                                propItem.UpdatedAt   = DateTimeOffset.UtcNow;
                                propItem.ModifiedBy  = account.Email;
                            }
                        }
                    }
                    //context.SaveChanges();



                    //    var IsIsaolated = context.PropertyStatusMstr.Where(i => i.Id == item.StatusId).Select(i => i.Status).FirstOrDefault();
                    //if (IsIsaolated == "Isolated")
                    //{

                    //    }
                    //    //context.SaveChanges();
                    //}
                    //else
                    //{
                    //    var prop = context.Properties.Where(i => i.Id == item.PropertyId).ToList();
                    //    if (prop != null && prop.Count > 0)
                    //    {

                    //        foreach (var propItem in prop)
                    //        {
                    //            propItem.StatusId = item.StatusId;
                    //            propItem.SubStatusId = item.PropertySubStatusMstrsId;
                    //            propItem.UpdatedAt = DateTimeOffset.UtcNow;
                    //            propItem.ModifiedBy = account.Email;
                    //        }

                    //    }
                }
                context.SaveChanges();
                //var IncidentId = context.Properties.FirstOrDefault(i => i.Id == item.PropertyId).IncidentId;
                //DbUtilities.PropertyStatusCount(IncidentId);
                return(Ok());
            }
            catch (Exception ex)
            {
                HttpUtilities.ServerError(ex, Request);
                return(null);
            }
        }