Exemplo n.º 1
0
        public int UpdateUser(UserInfoModel userInfo, int permission)
        {
            int result = 0;

            try
            {
                if (permission == 1)
                {
                    var userDetail = unitOfWork.DbContext.UserDetail.Where(ud => ud.ID == userInfo.UserId).FirstOrDefault();
                    if (userDetail != null)
                    {
                        userDetail.Name          = userInfo.FirstName;
                        userDetail.CompanyName   = userInfo.Company;
                        userDetail.Email         = userInfo.Email;
                        userDetail.UserTelephone = userInfo.Contact;
                        userDetail.Dob           = userInfo.DOB;

                        PermissionLevelMapping PermissionLevelMapping = new PermissionLevelMapping()
                        {
                            UserDetail   = userDetail,
                            PermissionId = userInfo.Permission,
                            CreationDate = DateTime.UtcNow
                        };

                        unitOfWork.DbContext.PermissionLevelMappings.Add(PermissionLevelMapping);

                        unitOfWork.DbContext.SaveChanges();
                        result = 1;
                    }
                    else
                    {
                        throw new NoDataFoundException();
                    }


                    return(result);
                }
                else
                {
                    throw new PermissionDeniedException();
                }
            }
            catch (BaseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public int AddNewUser(List <UserInfoModel> userInfoModel, int permission)
        {
            int           result       = 0;
            List <String> mailIdsList  = new List <string>();
            List <String> passwordList = new List <string>();

            try
            {
                if (permission == 1)
                {
                    foreach (UserInfoModel userInfo in userInfoModel)
                    {
                        var userIsPresent = unitOfWork.DbContext.UserDetail
                                            .Any(ud => String.Compare(ud.Email, userInfo.Email, true) == 0
                                                 );
                        if (userIsPresent)
                        {
                            throw new UserAlreadyPresentException();
                        }
                        else
                        {
                            userInfo.PasswordToMail = PasswordManager.GeneratePassword1();
                            string salt = String.Empty;
                            userInfo.Password = PasswordManager.GeneratePasswordHash(userInfo.PasswordToMail, out salt);
                            UserDetail userDetail = new UserDetail
                            {
                                Name     = userInfo.FirstName + " " + userInfo.LastName,
                                Email    = userInfo.Email,
                                Password = userInfo.Password,
                                //RegisteredDate = DateTime.UtcNow,
                                UserTelephone = userInfo.Contact,
                                CompanyName   = userInfo.Company,
                                Dob           = userInfo.DOB,
                                Salt          = salt,
                                SetByAdmin    = true
                            };


                            //masterContext.UserDetail.Add(userDetail);
                            PermissionLevelMapping permissionMappingTable = new PermissionLevelMapping()
                            {
                                UserDetail   = userDetail,
                                PermissionId = userInfo.Permission,
                                CreationDate = DateTime.UtcNow
                            };

                            PasswordResetMapping passwordResetMapping = new PasswordResetMapping()
                            {
                                UserDetail      = userDetail,
                                PasswordResetOn = DateTime.UtcNow,
                            };


                            unitOfWork.DbContext.PermissionLevelMappings.Add(permissionMappingTable);
                            unitOfWork.DbContext.PasswordResetMapping.Add(passwordResetMapping);
                            mailIdsList.Add(userDetail.Email);
                            passwordList.Add(userInfo.PasswordToMail);
                        }
                    }

                    unitOfWork.DbContext.SaveChanges();

                    foreach (var mp in mailIdsList.Zip(passwordList, Tuple.Create))
                    {
                        SendMail.SendMailForRegistration(mp.Item1, mp.Item2);
                    }

                    result = 1;
                    return(result);
                }
                else
                {
                    throw new PermissionDeniedException();
                }
            }
            catch (UserServiceException ex)
            {
                throw ex;
            }
            catch (BaseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }