/// <summary> /// updates password /// </summary> /// <param name="userDto"></param> /// <returns></returns> public bool UpdatePassword(Business.UserLoginDTO userDto) { Domain.UserLogin user = _m3pactContext.UserLogin.FirstOrDefault(x => x.UserId == userDto.UserId); if (user != null) { user.Password = userDto.Password; user.ForgotPasswordToken = userDto.ForgotPasswordToken; user.LastPasswordChanged = userDto.LastPasswordChanged; user.ModifiedBy = userContext.UserId; user.ModifiedDate = DateTime.UtcNow; _m3pactContext.Update(user); return(_m3pactContext.SaveChanges() > 0); } return(false); }
/// <summary> /// Saves client User /// </summary> /// <param name="userLogin"></param> /// <returns></returns> public bool SaveUser(Business.UserLoginDTO userLogin) { try { List <Domain.UserClientMap> userClientMapList = new List <DomainModel.DomainModels.UserClientMap>(); Domain.UserLogin existingClientUser = _m3pactContext.UserLogin.FirstOrDefault(x => x.UserId == userLogin.UserId); List <int> clientIdList = new List <int>(); if (userLogin.Client.Count > 0) { foreach (Business.ClientDetails client in userLogin.Client) { clientIdList.Add(_m3pactContext.Client.FirstOrDefault(x => x.ClientCode == client.ClientCode).ClientId); } } if (existingClientUser != null) { List <int> insertableClients = new List <int>(); MapClientUser(userLogin, existingClientUser, true); PrepareChangedClientMaps(userLogin, existingClientUser, clientIdList, insertableClients); userClientMapList = MapUserClientMap(existingClientUser, insertableClients); _m3pactContext.UserClientMap.AddRange(userClientMapList); } else { Domain.UserLogin insertableClientUser = new Domain.UserLogin(); MapClientUser(userLogin, insertableClientUser, false); _m3pactContext.UserLogin.Add(insertableClientUser); userClientMapList = MapUserClientMap(insertableClientUser, clientIdList); _m3pactContext.UserClientMap.AddRange(userClientMapList); } int i = _m3pactContext.SaveChanges(); return(i > 0); } catch (Exception ex) { throw ex; } }