Esempio n. 1
0
        public CustomerLoginModel IsUserExist(CustomerLoginModel _Dto, string userip)
        {
            try
            {
                //using (DatabaseEntities DatabaseEntities = new DatabaseEntities())
                //{
                db = new DatabaseEntities();

                //string dd = PasswordManager.DecryptText("aWIbcZIuvxlFajh8TMADjrxSKlmndmUM");

                string EMPPassword = PasswordManager.CryptText(_Dto.EMPPassword);
                //string EMPPasswordTest = PasswordManager.DecryptText(_Dto.EMPPassword);

                var data = (from user in db.UserMasters
                            join entMas in db.EntityMasters on user.EntityId equals entMas.Id
                            where user.UserName == _Dto.EMPUserId && user.Password == EMPPassword // _Dto.EMPPassword
                            select new { user, entMas }).FirstOrDefault();

                if (data != null)
                {
                    _Dto.Id = data.user.Id;
                    _Dto.CustomerOfficeId = data.user.Id;
                    //_Dto.EFIN = data.Id;
                    _Dto.TaxOfficeUsername     = data.user.UserName;
                    _Dto.CrossLinkUserId       = data.user.UserName;
                    _Dto.EntityID              = data.user.EntityId;//.ToString();
                    _Dto.IsChangedPassword     = true;
                    _Dto.IsSetSecurityQuestion = true;
                    //_Dto.EntityDisplayID = data.entMas.Id;
                    _Dto.BaseEntityId           = data.entMas.BaseEntityId;
                    _Dto.IsActivationCompleted  = 1;
                    _Dto.IsVerified             = true;
                    _Dto.uTaxNotCollectingSBFee = true;

                    var permissions = new Sitemap.SitemapService().GetUserRolePermissions(data.user.Id);
                    _Dto.IsnewCustomers = permissions.NewCustomer.ViewPermission;
                    _Dto.IsOfficeMgmt   = permissions.OfficeManamgement.ViewPermission;
                    _Dto.FeeReport      = permissions.ReportPermissions.FeeReport;
                    _Dto.NoBankApp      = permissions.ReportPermissions.NoBankApp;
                    _Dto.Enrollstatus   = permissions.ReportPermissions.Enrollstatus;
                    _Dto.LoginReport    = permissions.ReportPermissions.LoginReport;
                }

                if (data != null)
                {
                    _Dto.Token = _TokenService.GenerateToken(data.user.Id, userip);
                }
                else
                {
                    _Dto = Get(_Dto, userip);
                }
                return(_Dto);
                // }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex.ToString(), "CustomerLogin/IsUserExist", Guid.Empty);
                return(null);
            }
        }
Esempio n. 2
0
        public AccountDTO IsUserExist(string userName, string password)
        {
            //string ClientIP = Request.GetClientIpAddress();
            using (DatabaseEntities DatabaseEntities = new DatabaseEntities())
            {
                string uTaxPassword = PasswordManager.CryptText(password);

                var usermaster = (from user in DatabaseEntities.UserMasters
                                  where user.UserName == userName && user.Password == uTaxPassword//password
                                  select user).FirstOrDefault();

                if (usermaster != null)
                {
                    _AccountDto.Id       = usermaster.Id;
                    _AccountDto.Email    = usermaster.EmailAddress;
                    _AccountDto.Name     = usermaster.FirstName + " " + usermaster.LastName;
                    _AccountDto.UserName = usermaster.UserName;
                    _AccountDto.Token    = _TokenService.GenerateToken(_AccountDto.Id);

                    usermaster.LastLoginDate   = DateTime.Now;
                    db.Entry(usermaster).State = System.Data.Entity.EntityState.Modified;
                    DatabaseEntities.SaveChanges();
                }

                return(_AccountDto);
            }
        }
Esempio n. 3
0
        public bool ResetPassword(string passwordHash, Guid UserId)
        {
            try
            {
                using (DatabaseEntities DatabaseEntities = new DatabaseEntities())
                {
                    string uTaxPassword = PasswordManager.CryptText(passwordHash);
                    var usermaster = (from user in DatabaseEntities.UserMasters
                                      where user.Id == UserId
                                      select user).FirstOrDefault();

                    usermaster.LastLoginDate = DateTime.Now;
                    db.Entry(usermaster).State = System.Data.Entity.EntityState.Modified;
                    usermaster.Password = uTaxPassword;// passwordHash;
                    DatabaseEntities.SaveChanges();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
                throw ex.InnerException;

            }
            finally
            {

            }
        }
Esempio n. 4
0
        public bool SaveMyPassword(string currentpassword, string password, Guid Id)
        {
            try
            {
                var IsCorrect = false;
                emp_CustomerLoginInformation _CustomerLoginInformation = new emp_CustomerLoginInformation();

                string EMPPassword = PasswordManager.CryptText(currentpassword);

                _CustomerLoginInformation = db.emp_CustomerLoginInformation.Where(o => o.CustomerOfficeId == Id && o.EMPPassword == EMPPassword).FirstOrDefault();
                if (_CustomerLoginInformation != null)
                {
                    string uTaxPassword = PasswordManager.CryptText(password);
                    _CustomerLoginInformation.EMPPassword     = uTaxPassword;// password;
                    _CustomerLoginInformation.StatusCode      = EMPConstants.Active;
                    _CustomerLoginInformation.LastUpdatedBy   = Id;
                    _CustomerLoginInformation.LastUpdatedDate = DateTime.Now;

                    db.Entry(_CustomerLoginInformation).State = System.Data.Entity.EntityState.Modified;
                    IsCorrect = true;
                }
                else
                {
                    var UserMaster = db.UserMasters.Where(o => o.Id == Id && o.Password == EMPPassword).FirstOrDefault();
                    if (UserMaster != null)
                    {
                        string uTaxPassword = PasswordManager.CryptText(password);
                        UserMaster.Password        = uTaxPassword;// password;
                        UserMaster.StatusCode      = EMPConstants.Active;
                        UserMaster.LastUpdatedBy   = Id;
                        UserMaster.LastUpdatedDate = DateTime.Now;

                        db.Entry(UserMaster).State = System.Data.Entity.EntityState.Modified;
                        IsCorrect = true;
                    }
                }


                if (!IsCorrect)
                {
                    return(false);
                }

                try
                {
                    db.SaveChanges();
                    return(true);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    ExceptionLogger.LogException(ex.ToString(), "ChangePassword/update", Id);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex.ToString(), "ChangePassword/update", Id);
                return(false);
            }
        }
Esempio n. 5
0
        public string updatexlinkdetails(xlinkModel model)
        {
            try
            {
                db = new DatabaseEntities();
                var isexist = (from s in db.UtaxCrosslinkDetails
                               where s.CLAccountId == model.CLAccountId && s.StatusCode == EMPConstants.Active
                               select s).FirstOrDefault();
                if (model.Id == 0)
                {
                    if (isexist != null)
                        return "Exists";

                    UtaxCrosslinkDetail detail = new UtaxCrosslinkDetail();
                    detail.CreatedBy = model.UserId;
                    detail.CreatedDate = DateTime.Now;
                    detail.Password = model.Password == "" ? "" : PasswordManager.CryptText(model.Password);
                    detail.StatusCode = EMPConstants.Active;
                    detail.CLAccountId = model.CLAccountId;
                    detail.CLAccountPassword = PasswordManager.CryptText(model.CLAccountPassword);
                    detail.CLLogin = model.CLLogin;

                    detail.UpdatedBy = model.UserId;
                    detail.UpdatedDate = DateTime.Now;
                    detail.Username = model.MasterId;
                    db.UtaxCrosslinkDetails.Add(detail);
                    db.SaveChanges();
                }
                else if (model.Id != 0)
                {
                    if (isexist != null)
                    {
                        if (isexist.Id != model.Id)
                            return "Exists";
                    }
                    var data = db.UtaxCrosslinkDetails.Where(x => x.Id == model.Id).FirstOrDefault();
                    if (data != null)
                    {
                        data.Username = model.MasterId;
                        data.Password = model.Password == "" ? "" : PasswordManager.CryptText(model.Password);
                        data.StatusCode = EMPConstants.Active;

                        data.CLAccountId = model.CLAccountId;
                        data.CLAccountPassword = PasswordManager.CryptText(model.CLAccountPassword);
                        data.CLLogin = model.CLLogin;

                        data.UpdatedBy = model.UserId;
                        data.UpdatedDate = DateTime.Now;
                        db.SaveChanges();
                    }
                }
                return "Success";
            }
            catch (Exception)
            {
                return "Fail";
            }
        }
Esempio n. 6
0
        public Guid Save(ResetPasswordModel _Dto, Guid Id, int EntityState)
        {
            try
            {
                emp_CustomerLoginInformation _CustomerLoginInformation = new emp_CustomerLoginInformation();

                if (_Dto != null)
                {
                    string EMPPassword = PasswordManager.CryptText(_Dto.EMPPassword);

                    _CustomerLoginInformation.Id               = Id;
                    _CustomerLoginInformation.EMPPassword      = EMPPassword;
                    _CustomerLoginInformation.CustomerOfficeId = _Dto.CustomerOfficeId;
                    _CustomerLoginInformation.CreatedDate      = DateTime.Now;
                    _CustomerLoginInformation.StatusCode       = EMPConstants.Active;
                }

                if (EntityState == (int)System.Data.Entity.EntityState.Modified)
                {
                    _CustomerLoginInformation.LastUpdatedBy   = _Dto.UserId;
                    _CustomerLoginInformation.LastUpdatedDate = DateTime.Now;

                    db.Entry(_CustomerLoginInformation).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    _CustomerLoginInformation.CreatedBy       = _Dto.UserId;
                    _CustomerLoginInformation.CreatedDate     = DateTime.Now;
                    _CustomerLoginInformation.LastUpdatedBy   = _Dto.UserId;
                    _CustomerLoginInformation.LastUpdatedDate = DateTime.Now;
                    db.emp_CustomerLoginInformation.Add(_CustomerLoginInformation);
                }

                try
                {
                    db.SaveChanges();
                    return(_CustomerLoginInformation.Id);
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!IsExists(_CustomerLoginInformation.Id))
                    {
                        return(_CustomerLoginInformation.Id);
                    }
                    else
                    {
                        return(Guid.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex.ToString(), "ResetPassword/PostResetPassword", Id);
                return(Guid.Empty);
            }
        }
Esempio n. 7
0
        // public DatabaseEntities db = new DatabaseEntities();

        //public IQueryable<ChangePasswordModel> GetAll()
        //{
        //    db = new DatabaseEntities();
        //    var data = db.emp_CustomerLoginInformation.Select(o => new ChangePasswordModel
        //    {
        //        Id = o.Id,
        //        EMPPassword = o.EMPPassword,
        //        CustomerOfficeId = o.CustomerOfficeId,
        //        StatusCode = o.StatusCode
        //    }).DefaultIfEmpty();
        //    return data;
        //}

        public CustomerLoginModel Get(CustomerLoginModel _Dto, string userip)
        {
            try
            {
                DropDownService           ddService           = new DropDownService();
                List <EntityHierarchyDTO> EntityHierarchyDTOs = new List <EntityHierarchyDTO>();

                db = new DatabaseEntities();
                //var data2 = db.emp_CustomerLoginInformation.ToList();
                string EMPPassword = PasswordManager.CryptText(_Dto.EMPPassword); // _Dto.EMPPassword
                var    data        = (from ci in db.emp_CustomerInformation
                                      join cli in db.emp_CustomerLoginInformation on ci.Id equals cli.CustomerOfficeId
                                      join entMas in db.EntityMasters on ci.EntityId equals entMas.Id
                                      where cli.EMPUserId == _Dto.EMPUserId && cli.EMPPassword == EMPPassword && (ci.StatusCode == EMPConstants.Active || ci.StatusCode == EMPConstants.Pending)
                                      //&& ci.IsHold != true//ci.StatusCode == EMPConstants.Created ||
                                      select new { ci, cli, EntityId = entMas.Id, entMas.BaseEntityId }).FirstOrDefault();

                if (data != null)
                {
                    if ((data.ci.IsHold ?? false) && data.ci.EntityId != (int)EMPConstants.Entity.SO && data.ci.EntityId != (int)EMPConstants.Entity.MO && data.ci.EntityId != (int)EMPConstants.Entity.SVB)
                    {
                        _Dto.Id      = Guid.Empty;
                        _Dto.Message = "Your site has been placed on hold, please contact your Software Provider";
                        return(_Dto);
                    }
                    _Dto.Id = data.cli.Id;
                    _Dto.CustomerOfficeId = data.cli.CustomerOfficeId;

                    //11212016
                    _Dto.EFIN       = data.ci.EFIN;
                    _Dto.EFINStatus = data.ci.EFINStatus;

                    _Dto.TaxOfficeUsername = data.cli.TaxOfficeUsername;
                    _Dto.CrossLinkUserId   = data.cli.CrossLinkUserId;

                    _Dto.IsChangedPassword     = (data.cli.CrossLinkPassword == data.cli.EMPPassword) ? true : false;
                    _Dto.IsSetSecurityQuestion = db.SecurityAnswerUserMaps.Where(o => o.UserId == data.cli.CustomerOfficeId).Any();
                    _Dto.Token       = _TokenService.GenerateToken(data.ci.Id, userip);
                    _Dto.ParentID    = data.ci.ParentId.ToString();
                    _Dto.SalesYearID = data.ci.SalesYearID.ToString();
                    //_Dto.EntityDisplayID = data.DisplayId;
                    _Dto.BaseEntityId = data.BaseEntityId;
                    // _Dto.EntityID = data.EntityId;
                    _Dto.EntityID = data.ci.EntityId;//.ToString();

                    _Dto.IsMSOUser             = data.ci.IsMSOUser ?? false;
                    _Dto.IsActivationCompleted = data.ci.IsActivationCompleted ?? 0;
                    _Dto.IsEnrollmentSubmit    = new SubSiteFeeService().IsEnrollmentSubmit(data.ci.Id);
                    _Dto.IsVerified            = data.ci.IsVerified ?? false;

                    _Dto.uTaxNotCollectingSBFee = data.ci.uTaxNotCollectingSBFee ?? false;

                    _Dto.IsTaxReturn = true;
                    if (data.ci.ParentId == Guid.Empty || data.ci.ParentId == null)
                    {
                        var taxreturn = db.MainOfficeConfigurations.Where(x => x.emp_CustomerInformation_ID == data.ci.Id && x.StatusCode == EMPConstants.Active).FirstOrDefault();
                        if (taxreturn != null)
                        {
                            _Dto.IsTaxReturn = taxreturn.IsSiteTransmitTaxReturns;
                        }
                    }
                    _Dto.IsHold = data.ci.IsHold ?? false;

                    Guid TopParentId = Guid.Empty;
                    EntityHierarchyDTOs = ddService.GetEntityHierarchies(data.ci.Id);
                    var TopFromHierarchy = EntityHierarchyDTOs.OrderByDescending(o => o.Customer_Level).FirstOrDefault();
                    TopParentId = TopFromHierarchy.CustomerId ?? Guid.Empty;

                    DefaultBankModel DefaultBank = new DefaultBankModel();

                    DefaultBank = (from enrollbank in db.EnrollmentBankSelections
                                   where enrollbank.CustomerId == data.cli.CustomerOfficeId && enrollbank.StatusCode == EMPConstants.Active && enrollbank.BankSubmissionStatus == 1
                                   orderby enrollbank.BankSubmissionStatus descending, enrollbank.LastUpdatedDate descending
                                   select new DefaultBankModel {
                        BankId = enrollbank.BankId, BankSubmissionStatus = enrollbank.BankSubmissionStatus ?? 0, LastUpdatedDate = enrollbank.LastUpdatedDate
                    }).FirstOrDefault();

                    if (DefaultBank != null)
                    {
                        _Dto.BankId = DefaultBank.BankId;
                    }
                    else
                    {
                        DefaultBankModel DefaultBank2 = (from enrollbank in db.EnrollmentBankSelections
                                                         where enrollbank.CustomerId == data.cli.CustomerOfficeId && enrollbank.StatusCode == EMPConstants.Active
                                                         orderby enrollbank.BankSubmissionStatus descending, enrollbank.LastUpdatedDate descending
                                                         select new DefaultBankModel {
                            BankId = enrollbank.BankId, BankSubmissionStatus = enrollbank.BankSubmissionStatus ?? 0, LastUpdatedDate = enrollbank.LastUpdatedDate
                        }).FirstOrDefault();

                        if (DefaultBank2 != null)
                        {
                            _Dto.BankId = DefaultBank2.BankId;
                        }
                    }


                    if (_Dto.EntityID != (int)EMPConstants.Entity.SO && _Dto.EntityID != (int)EMPConstants.Entity.SOME && _Dto.EntityID != (int)EMPConstants.Entity.SOME_SS && _Dto.BankId != Guid.Empty)
                    {
                        var SSBConfig = db.SubSiteBankConfigs.Where(o => o.emp_CustomerInformation_ID == TopParentId && o.BankMaster_ID == _Dto.BankId).ToList();
                        if (SSBConfig.Count() == 0)
                        {
                            _Dto.BankId = Guid.Empty;
                        }
                    }

                    if (TopParentId != Guid.Empty)
                    {
                        if (TopParentId == data.ci.Id)
                        {
                            _Dto.CanSubSiteLoginToEmp = true;
                        }
                        else
                        {
                            if (_Dto.BaseEntityId == (int)EMPConstants.BaseEntities.AE_SS)
                            {
                                // _Dto.CanSubSiteLoginToEmp = db.SubSiteOfficeConfigs.Where(a => a.RefId.ToString() == _Dto.ParentID).Select(a => a.CanSubSiteLoginToEmp ?? false).FirstOrDefault();
                                //var SupParentData = db.emp_CustomerInformation.Where(o => o.Id == data.ci.ParentId).FirstOrDefault();
                                //if (SupParentData != null)
                                //{
                                _Dto.SupParentID = TopParentId.ToString();

                                var sscExist = (from ssc in db.SubSiteConfigurations where ssc.emp_CustomerInformation_ID == TopParentId select ssc).FirstOrDefault();
                                if (sscExist != null)
                                {
                                    if (sscExist.IsuTaxManageingEnrolling == true)
                                    {
                                        _Dto.CanSubSiteLoginToEmp = true;
                                    }
                                    else
                                    {
                                        if (sscExist.IsuTaxPortalEnrollment == true)
                                        {
                                            _Dto.CanSubSiteLoginToEmp = true;
                                        }
                                        else
                                        {
                                            _Dto.CanSubSiteLoginToEmp = false;
                                        }
                                    }
                                }



                                var subSiteOfficeCo = (from ssc in db.SubSiteOfficeConfigs where ssc.RefId == _Dto.CustomerOfficeId select ssc).FirstOrDefault();
                                if (subSiteOfficeCo != null)
                                {
                                    if (subSiteOfficeCo.EFINListedOtherOffice == false)
                                    {
                                        _Dto.EFINOwnerUserId = false;
                                    }
                                    else
                                    {
                                        if (subSiteOfficeCo.SiteOwnthisEFIN == false)
                                        {
                                            _Dto.EFINOwnerUserId = true;
                                        }
                                        else
                                        {
                                            _Dto.EFINOwnerUserId = false;
                                        }
                                    }
                                }
                                //}
                            }
                            else
                            {
                                // _Dto.CanSubSiteLoginToEmp = db.SubSiteConfigurations.Where(a => a.emp_CustomerInformation_ID.ToString() == _Dto.ParentID).Select(a => a.CanSubSiteLoginToEmp).FirstOrDefault();

                                var sscExist = (from ssc in db.SubSiteConfigurations where ssc.emp_CustomerInformation_ID == TopParentId select ssc).FirstOrDefault();
                                if (sscExist != null)
                                {
                                    if (sscExist.IsuTaxManageingEnrolling == true)
                                    {
                                        _Dto.CanSubSiteLoginToEmp = true;
                                    }
                                    else
                                    {
                                        if (sscExist.IsuTaxPortalEnrollment == true)
                                        {
                                            _Dto.CanSubSiteLoginToEmp = true;
                                        }
                                        else
                                        {
                                            _Dto.CanSubSiteLoginToEmp = false;
                                        }
                                    }
                                }


                                var subSiteOfficeCo = (from ssc in db.SubSiteOfficeConfigs where ssc.RefId == _Dto.CustomerOfficeId select ssc).FirstOrDefault();
                                if (subSiteOfficeCo != null)
                                {
                                    if (subSiteOfficeCo.EFINListedOtherOffice == false)
                                    {
                                        _Dto.EFINOwnerUserId = false;
                                    }
                                    else
                                    {
                                        if (subSiteOfficeCo.SiteOwnthisEFIN == false)
                                        {
                                            _Dto.EFINOwnerUserId = true;
                                        }
                                        else
                                        {
                                            _Dto.EFINOwnerUserId = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        _Dto.CanSubSiteLoginToEmp = true;
                    }


                    if (_Dto.EntityID == (int)EMPConstants.Entity.SOME_SS)
                    {
                        _Dto.CanSubSiteLoginToEmp = true;
                    }

                    EntityHierarchyDTOs = ddService.GetEntityHierarchies(_Dto.Id);

                    Guid ParentId = Guid.Empty;
                    int  Level    = EntityHierarchyDTOs.Count;
                    if (EntityHierarchyDTOs.Count > 0)
                    {
                        var LevelOne = EntityHierarchyDTOs.OrderByDescending(o => o.Customer_Level).FirstOrDefault();
                        if (LevelOne != null)
                        {
                            ParentId = LevelOne.CustomerId ?? Guid.Empty;
                        }

                        if (EntityHierarchyDTOs.Count > 1)
                        {
                            _Dto.IsMSOUser = db.emp_CustomerInformation.Where(o => o.Id == ParentId).Select(o => o.IsMSOUser).FirstOrDefault() ?? false;
                        }
                    }
                }
                else
                {
                    return(null);
                }
                return(_Dto);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex.ToString(), "CustomerLogin/Get", Guid.Empty);
                return(null);
            }
        }
Esempio n. 8
0
        public async Task<int> SaveUser(UserDetailDTO _user, Guid Id, int EntityState)
        {
            UserMaster usermaster = new UserMaster();
            string Password = "";

            if (_user != null)
            {
                if (EntityState == (int)System.Data.Entity.EntityState.Modified)
                {
                    var Existuser = db.UserMasters.Where(o => o.Id != Id && o.UserName == _user.UserName).Any();
                    if (Existuser)
                        return -1;

                    usermaster = db.UserMasters.Where(o => o.Id == Id).FirstOrDefault();
                }
                else
                {
                    var Existuser = db.UserMasters.Where(o => o.UserName == _user.UserName).Any();
                    if (Existuser)
                        return -1;
                    Password = GetRandomPassword();
                    usermaster.Password = PasswordManager.CryptText(Password); //"admin1"

                }
                //usermaster.Id = "";
                usermaster.Id = Id;
                usermaster.EntityId = _user.EntityId;
                usermaster.CustomerId = _user.CustomerId;
                usermaster.FirstName = _user.FirstName;
                usermaster.LastName = _user.LastName;
                // usermaster.MiddleName = _user.MiddleName;
                usermaster.UserName = _user.UserName;

                usermaster.EmailAddress = _user.EmailAddress;
                usermaster.IsEmailConfirmed = _user.IsEmailConfirmed;
                usermaster.EmailConfirmationCode = _user.EmailConfirmationCode;
                usermaster.PasswordResetCode = _user.PasswordResetCode;

                usermaster.LastLoginDate = _user.LastLoginDate;
                usermaster.IsActive = true;
                usermaster.IsActiveDate = DateTime.Now;
                usermaster.StatusCode = EMPConstants.Active;

                if (EntityState == (int)System.Data.Entity.EntityState.Modified)
                {

                    usermaster.CreatedBy = _user.UserId;
                    usermaster.CreatedDate = DateTime.Now;
                    usermaster.LastUpdatedDate = DateTime.Now;
                    usermaster.LastUpdatedBy = _user.UserId;
                    db.Entry(usermaster).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    usermaster.LastUpdatedDate = DateTime.Now;
                    usermaster.LastUpdatedBy = _user.UserId;
                    db.UserMasters.Add(usermaster);

                    EmailNotification _email = new EmailNotification();
                    _email.CreatedBy = _user.UserId;
                    _email.CreatedDate = DateTime.Now;
                    _email.EmailCC = "";
                    _email.EmailContent = "";
                    _email.EmailSubject = EMPConstants.NewUserMailSubject;
                    _email.EmailTo = _user.EmailAddress;
                    _email.EmailType = (int)EMPConstants.EmailTypes.NewAdminUser;
                    _email.IsSent = false;
                    _email.Parameters = _user.UserName + "$|$" + Password;
                    db.EmailNotifications.Add(_email);
                }


                // User Group Mapping Saving
                UserGroupMap usergroup = new UserGroupMap();

                UserGroupMapDTO UserGroupMapDto = await _UserGroupService.GetByUserId(usermaster.Id);
                bool IsNewGroup = true;
                if (UserGroupMapDto != null)
                {
                    if (UserGroupMapDto.Id != Guid.Empty)
                    {
                        IsNewGroup = false;
                        usergroup.Id = UserGroupMapDto.Id;
                        usergroup.GroupId = _user.Groups.Id;
                        usergroup.UserId = usermaster.Id;
                        usergroup.StatusCode = EMPConstants.Active;
                        db.Entry(usergroup).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                if (IsNewGroup)
                {
                    usergroup.Id = Guid.NewGuid();
                    usergroup.GroupId = _user.Groups.Id;
                    usergroup.UserId = usermaster.Id;
                    usergroup.StatusCode = EMPConstants.Active;
                    db.UserGroupMaps.Add(usergroup);
                }

                if (_user.Roles.ToList().Count > 0)
                {
                    if (EntityState == (int)System.Data.Entity.EntityState.Modified)
                    {
                        var UserRole1 = db.UserRolesMaps.Where(o => o.UserId == _user.Id).ToList();
                        if (UserRole1.Count() > 0)
                            db.UserRolesMaps.RemoveRange(UserRole1);
                    }

                    List<UserRolesMap> _UserRolesMapList = new List<UserRolesMap>();
                    foreach (RoleDTO Role in _user.Roles)
                    {
                        UserRolesMap _UserRolesMap = new UserRolesMap();
                        _UserRolesMap.Id = Guid.NewGuid();
                        _UserRolesMap.UserId = usermaster.Id;
                        _UserRolesMap.RoleId = Role.Id;
                        _UserRolesMap.StatusCode = EMPConstants.Active;
                        _UserRolesMapList.Add(_UserRolesMap);
                    }

                    db.UserRolesMaps.AddRange(_UserRolesMapList);
                }
            }

            try
            {

                await db.SaveChangesAsync();
                db.Dispose();

                return 1;
            }

            catch (DbUpdateConcurrencyException)
            {
                return 0;
            }
        }
Esempio n. 9
0
        public int Save(CustomerLoginInformationModel model)
        {
            int entityState = 0;
            emp_CustomerLoginInformation customerLoginInformation = new emp_CustomerLoginInformation();

            if (model != null)
            {
                Guid newguid1;
                Guid CustomerOfficeId = model.CustomerOfficeId ?? Guid.Empty;
                if (Guid.TryParse(model.Id, out newguid1))
                {
                    //var ExistCust = db.emp_CustomerLoginInformation.Any(a => a.EFIN == model.EFIN && a.Id != newguid1);
                    //if (ExistCust)
                    //    return -1;

                    //11212016 - If

                    int EFIN = model.EFIN ?? 0;
                    if (EFIN > 0 && (model.EFINStatus == 16 || model.EFINStatus == 19))
                    {
                        //if (CustomerOfficeId != Guid.Empty)
                        //{
                        var ExistCust = db.emp_CustomerInformation.Any(a => a.EFIN == model.EFIN && a.Id != CustomerOfficeId);
                        if (ExistCust)
                        {
                            return(-1);
                        }
                        //}
                    }

                    var ExistCrossCust = db.emp_CustomerLoginInformation.Any(a => a.CrossLinkUserId == model.CrossLinkUserId && a.Id != newguid1);
                    if (ExistCrossCust)
                    {
                        return(-2);
                    }
                }

                if (string.IsNullOrEmpty(model.Id))
                {
                    customerLoginInformation.Id = Guid.NewGuid();
                }
                else
                {
                    Guid newguid;
                    if (Guid.TryParse(model.Id, out newguid))
                    {
                        customerLoginInformation.Id = newguid;
                        entityState = (int)System.Data.Entity.EntityState.Modified;
                    }
                }

                // customerLoginInformation.EFIN = model.EFIN;
                customerLoginInformation.MasterIdentifier  = model.MasterIdentifier;
                customerLoginInformation.CrossLinkUserId   = model.CrossLinkUserId;
                customerLoginInformation.CrossLinkPassword = PasswordManager.CryptText(model.CrossLinkPassword);// model.CrossLinkPassword;
                customerLoginInformation.OfficePortalUrl   = model.OfficePortalUrl;
                customerLoginInformation.TaxOfficeUsername = model.TaxOfficeUsername;
                customerLoginInformation.TaxOfficePassword = PasswordManager.CryptText(model.TaxOfficePassword); // model.TaxOfficePassword;
                customerLoginInformation.CustomerOfficeId  = model.CustomerOfficeId;
                customerLoginInformation.EMPPassword       = PasswordManager.CryptText(model.EMPPassword);       //model.EMPPassword;
                customerLoginInformation.EMPUserId         = model.EMPUserId;
                customerLoginInformation.StatusCode        = EMPConstants.Active;

                customerLoginInformation.CLAccountId       = model.CLAccountId;
                customerLoginInformation.CLLogin           = model.CLLogin;
                customerLoginInformation.CLAccountPassword = string.IsNullOrEmpty(model.CLAccountPassword) ? "" : PasswordManager.CryptText(model.CLAccountPassword);

                if (entityState == (int)System.Data.Entity.EntityState.Modified)
                {
                    customerLoginInformation.CreatedDate     = DateTime.Now;
                    customerLoginInformation.LastUpdatedDate = DateTime.Now;
                    customerLoginInformation.LastUpdatedBy   = model.UserId;
                    customerLoginInformation.CreatedBy       = model.UserId;
                    db.Entry(customerLoginInformation).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    db.Entry(customerLoginInformation).State = System.Data.Entity.EntityState.Added;
                    customerLoginInformation.LastUpdatedBy   = model.UserId;
                    customerLoginInformation.LastUpdatedDate = DateTime.Now;
                    db.emp_CustomerLoginInformation.Add(customerLoginInformation);
                }

                emp_CustomerInformation empCustInfo = new emp_CustomerInformation();
                empCustInfo = db.emp_CustomerInformation.Where(o => o.Id == model.CustomerOfficeId).FirstOrDefault();
                if (empCustInfo != null)
                {
                    //11212016 - 2
                    empCustInfo.EFIN          = model.EFIN;
                    empCustInfo.EFINStatus    = model.EFINStatus;
                    empCustInfo.StatusCode    = empCustInfo.IsActivationCompleted == 1 ? EMPConstants.Active : EMPConstants.Created;
                    empCustInfo.CreatedBy     = model.UserId;
                    empCustInfo.LastUpdatedBy = model.UserId;

                    if (empCustInfo.EntityId == (int)EMPConstants.Entity.SO || empCustInfo.EntityId == (int)EMPConstants.Entity.SOME)
                    {
                        if (empCustInfo.StatusCode == EMPConstants.Active || empCustInfo.IsActivationCompleted == 1)
                        {
                            empCustInfo.StatusCode            = EMPConstants.Active;
                            empCustInfo.IsActivationCompleted = 1;
                            empCustInfo.AccountStatus         = "Active";
                            if (empCustInfo.EntityId == (int)EMPConstants.Entity.SO)
                            {
                                empCustInfo.EROType = "Single Office";
                            }
                            else if (empCustInfo.EntityId == (int)EMPConstants.Entity.SOME)
                            {
                                empCustInfo.EROType = "SOME";
                            }
                        }
                    }

                    empCustInfo.CreatedDate     = System.DateTime.Now;
                    empCustInfo.LastUpdatedDate = System.DateTime.Now;

                    db.Entry(empCustInfo).State = System.Data.Entity.EntityState.Modified;
                }
            }
            try
            {
                db.SaveChanges();
                db.Dispose();

                if (model != null)
                {
                    if (model.CustomerOfficeId != Guid.Empty)
                    {
                        DropDownService ddService = new DropDownService();
                        var             items     = ddService.GetBottomToTopHierarchy(model.CustomerOfficeId ?? Guid.Empty);
                    }
                }

                return(1);
            }
            catch (Exception ex)
            {
                EMPPortal.Core.Utilities.ExceptionLogger.LogException(ex.ToString(), "CustomerLoginInformationService/Save", Guid.Empty);
                return(0);

                throw;
            }
        }