public async Task <bool> AddUserToCompany(int companyId, string email)
        {
            UserDto user = await GetUserByEmail(email);

            List <CompanyRoleDto> userRoles = await GetCompanyRolesFromUser(companyId, user.ID);

            foreach (CompanyRoleDto role in userRoles)
            {
                if (role.CompanyId == companyId)
                {
                    return(false);
                }
            }

            int defaultRoleId = (await GetDefaultCompanyRole(companyId)).Id;

            UserCompanyRole userRole = new UserCompanyRole
            {
                CompanyRoleId = defaultRoleId,
                UserId        = user.ID
            };

            await AddAsync(userRole);

            return(true);
        }
示例#2
0
        public void CanEdit_CheckCompanyIdAndRole(int companyId, int userCompanyId, UserCompanyRole role, bool result)
        {
            var user = new User("", "", role, "");

            user.From(new CompanyId(userCompanyId));

            var canEdit = user.CanEdit(new CompanyId(companyId));

            Assert.That(canEdit, Is.EqualTo(result));
        }
        public async Task <bool> RemoveRoleFromCompanyUser(int roleId, int userId)
        {
            UserCompanyRole userRole = await _context.UserCompanyRoles.FirstOrDefaultAsync(x => x.CompanyRoleId == roleId && x.UserId == userId);

            if (userRole != null)
            {
                await DeleteAsync(userRole);

                return(true);
            }
            return(false);
        }
        public async Task <List <CompanyRoleDto> > AddRoleToCompanyUser(int companyId, int userId, int roleId)
        {
            UserCompanyRole userRole = new UserCompanyRole
            {
                CompanyRoleId = roleId,
                UserId        = userId
            };

            await AddAsync(userRole);

            return(null);
        }
        //private async Task<List<Error>> SaveGrid1(UserRoleVm grid1, IEnumerable<KeyValuePair<string, ModelState>> state, UserViewModel record)
        //{
        //    List<Error> errors = new List<Error>();


        //    IdentityResult re = new IdentityResult();
        //    // updated records
        //    if (grid1.updated != null)
        //    {
        //        foreach (var model in grid1.updated)
        //        {
        //            if (model.IsChecked)
        //            {
        //                if (!_userManager.IsInRole(record.Id, model.Name))
        //                    re = await _userManager.AddToRoleAsync(record.Id, model.Name);
        //            }
        //            else
        //            {
        //                if (_userManager.IsInRole(record.Id, model.Name))
        //                    re = await _userManager.RemoveFromRoleAsync(record.Id, model.Name);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        if (record.NewUser)
        //        {
        //            await _userManager.AddToRoleAsync(record.Id, "Employee");
        //        }
        //    }
        //    if (re.Errors.Count() > 0)
        //    {
        //        foreach (var error in re.Errors)
        //        {
        //            ErrorMessage mess = new ErrorMessage()
        //            {
        //                message = MsgUtils.Instance.Trls(error)
        //            };
        //            Error er = new Error();
        //            er.errors.Add(mess);
        //            return errors;
        //        }
        //    }

        //    return errors;
        //}
        private List <Error> SaveGrid(UserCompaniesVM grid, IEnumerable <KeyValuePair <string, ModelState> > state, ApplicationUser user)
        {
            List <Error> errors = new List <Error>();

            // Deleted
            if (grid.deleted != null)
            {
                foreach (var model in grid.deleted)
                {
                    var companyrole = new UserCompanyRole
                    {
                        Id = model.Id
                    };

                    db.UserCompanyRoles.Remove(companyrole);
                }
            }

            // updated records
            if (grid.updated != null)
            {
                foreach (var model in grid.updated)
                {
                    var companyrole = new UserCompanyRole();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = companyrole, Source = model, Transtype = TransType.Update
                    });

                    db.UserCompanyRoles.Attach(companyrole);
                    db.Entry(companyrole).State = EntityState.Modified;
                }
            }

            // inserted records
            if (grid.inserted != null)
            {
                foreach (var model in grid.inserted)
                {
                    var companyrole = new UserCompanyRole();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = companyrole, Source = model, Transtype = TransType.Insert
                    });
                    companyrole.User = user;
                    db.UserCompanyRoles.Add(companyrole);
                }
            }

            return(errors);
        }
示例#6
0
        public void CreateNew_CreateWithNullId_WhenAllPropertyAreNotEmpty()
        {
            const string          lastName    = "name";
            const string          firstName   = "number";
            const UserCompanyRole companyRole = UserCompanyRole.Admin;
            const string          email       = "email";

            var company = new User(lastName, firstName, companyRole, email);

            Assert.That(company.IsNew, Is.True);
            Assert.That(company.FirstName, Is.EqualTo(lastName));
            Assert.That(company.LastName, Is.EqualTo(firstName));
            Assert.That(company.CompanyRole, Is.EqualTo(companyRole));
            Assert.That(company.Email, Is.EqualTo(email));
        }
示例#7
0
        private void SaveGrid(UserCompaniesVM grid, IEnumerable <KeyValuePair <string, ModelState> > state, ApplicationUser user, HrUnitOfWork unitOfWork, UserContext db)
        {
            // Deleted
            if (grid.deleted != null)
            {
                foreach (var model in grid.deleted)
                {
                    var companyrole = new UserCompanyRole
                    {
                        Id = model.Id
                    };

                    db.UserCompanyRoles.Remove(companyrole);
                }
            }

            // updated records
            if (grid.updated != null)
            {
                foreach (var model in grid.updated)
                {
                    var companyrole = new UserCompanyRole();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = companyrole, Source = model, Transtype = TransType.Update
                    }, unitOfWork);
                    companyrole.UserId = user.Id;
                    db.UserCompanyRoles.Attach(companyrole);
                    db.Entry(companyrole).State = EntityState.Modified;
                }
            }

            // inserted records
            if (grid.inserted != null)
            {
                foreach (var model in grid.inserted)
                {
                    var companyrole = new UserCompanyRole();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = companyrole, Source = model, Transtype = TransType.Insert
                    }, unitOfWork);
                    companyrole.User = user;
                    db.UserCompanyRoles.Add(companyrole);
                }
            }
        }
示例#8
0
        public override Object UpdateCompany <T>(T data)
        {
            BO.Signup signUPBO = (BO.Signup)(object) data;

            BO.User        userBO                = signUPBO.user;
            BO.Company     companyBO             = signUPBO.company;
            BO.AddressInfo addressBO             = signUPBO.addressInfo;
            BO.ContactInfo contactinfoBO         = signUPBO.contactInfo;
            BO.Role        roleBO                = signUPBO.role;
            Guid           invitationDB_UniqueID = Guid.NewGuid();

            Company         companyDB         = new Company();
            User            userDB            = new User();
            AddressInfo     addressDB         = new AddressInfo();
            ContactInfo     contactinfoDB     = new ContactInfo();
            UserCompany     userCompanyDB     = new UserCompany();
            UserCompanyRole userCompanyRoleDB = new UserCompanyRole();
            Invitation      invitationDB      = new Invitation();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                if (signUPBO == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (signUPBO.company == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (signUPBO.user == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (signUPBO.contactInfo == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                #region Company

                companyDB = _context.Companies.Where(p => p.id == companyBO.ID &&
                                                     (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                            .FirstOrDefault();

                if (companyDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Company Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                companyDB.TaxID = companyBO.TaxID;

                if (companyBO.SubsCriptionType != null)
                {
                    companyDB.SubscriptionPlanType = (int)companyBO.SubsCriptionType;
                }
                else
                {
                    companyDB.SubscriptionPlanType = null;
                }

                companyDB.CompanyStatusTypeID = 2; // CompanyStatusTypeID = 2 --- RegistrationComplete

                _context.SaveChanges();


                #endregion

                #region contactInfo
                contactinfoDB = _context.ContactInfoes.Where(p => p.id == contactinfoBO.ID &&
                                                             (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                                .FirstOrDefault();

                if (contactinfoDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Contact Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                contactinfoDB.CellPhone = contactinfoBO.CellPhone;

                _context.SaveChanges();

                #endregion

                #region User
                userDB = _context.Users.Where(p => p.id == userBO.ID &&
                                              (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

                if (userDB == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "User Record Not Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                userDB.FirstName = userBO.FirstName;
                userDB.LastName  = userBO.LastName;
                userDB.C2FactAuthEmailEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactEmail"));
                userDB.C2FactAuthSMSEnabled   = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactSMS"));

                #region password

                BO.ResetPassword resetPassword = new BO.ResetPassword();
                resetPassword.OldPassword = userDB.Password;
                //if (userDB != null)
                //{
                //        resetPassword.NewPassword = PasswordHash.HashPassword(userBO.Password);
                //        userDB.Password = resetPassword.NewPassword;
                // }
                if (userDB != null)
                {
                    if (companyDB.CompanyStatusTypeID == 2) //CompanyStatusTypeID == 2 --- Registration Complete
                    {
                        resetPassword.NewPassword     = PasswordHash.HashPassword(userBO.Password);
                        userDB.Password               = resetPassword.NewPassword;
                        companyDB.CompanyStatusTypeID = 3; //CompanyStatusTypeID = 3 --- Active
                    }
                }
                #endregion

                _context.SaveChanges();

                userDB = _context.Users.Where(p => p.id == userBO.ID &&
                                              (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

                #endregion

                dbContextTransaction.Commit();
            }

            BO.Company acc_ = Convert <BO.Company, Company>(companyDB);

            try
            {
                if (userDB != null)
                {
                    var updateCompany = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "CompanyUpdated".ToUpper()).FirstOrDefault();

                    if (updateCompany == null)
                    {
                        return(new BO.ErrorObject {
                            ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    else
                    {
                        #region Send mail to attorney
                        string msg1     = updateCompany.EmailBody;
                        string subject1 = updateCompany.EmailSubject;

                        string message1 = string.Format(msg1, userDB.FirstName);

                        BO.Email objEmail1 = new BO.Email {
                            ToEmail = userDB.UserName, Subject = subject1, Body = message1
                        };
                        objEmail1.SendMail();
                        #endregion
                    }
                }
            }
            catch (Exception ex) { }

            var res = (BO.GbObject)(object) acc_;
            return((object)res);
        }
示例#9
0
        public override Object Signup <T>(T data)
        {
            BO.Signup signUPBO = (BO.Signup)(object) data;

            bool flagUser = false;

            BO.User        userBO        = signUPBO.user;
            BO.Company     companyBO     = signUPBO.company;
            BO.AddressInfo addressBO     = signUPBO.addressInfo;
            BO.ContactInfo contactinfoBO = signUPBO.contactInfo;
            BO.Role        roleBO        = signUPBO.role;

            Company         companyDB         = new Company();
            User            userDB            = new User();
            AddressInfo     addressDB         = new AddressInfo();
            ContactInfo     contactinfoDB     = new ContactInfo();
            UserCompany     userCompanyDB     = new UserCompany();
            UserCompanyRole userCompanyRoleDB = new UserCompanyRole();
            Invitation      invitationDB      = new Invitation();

            if (string.IsNullOrEmpty(companyBO.TaxID) == false && _context.Companies.Any(o => o.TaxID == companyBO.TaxID))
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "TaxID already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }

            if (_context.Companies.Any(o => o.Name == companyBO.Name))
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Company already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error
                });
            }
            else if (_context.Users.Any(o => o.UserName == userBO.UserName))
            {
                flagUser = true;
            }

            #region Company

            companyDB.Name        = companyBO.Name;
            companyDB.id          = companyBO.ID;
            companyDB.TaxID       = companyBO.TaxID;
            companyDB.Status      = System.Convert.ToByte(companyBO.Status);
            companyDB.CompanyType = System.Convert.ToByte(companyBO.CompanyType);
            if (companyBO.SubsCriptionType.HasValue == true)
            {
                companyDB.SubscriptionPlanType = System.Convert.ToInt16(companyBO.SubsCriptionType);
            }
            else
            {
                companyDB.SubscriptionPlanType = null;
            }
            companyDB.CompanyStatusTypeID = 2; // CompanyStatusTypeID = 2 --- RegistrationComplete
            companyDB.BlobStorageTypeId   = 1;

            if (companyDB.IsDeleted.HasValue)
            {
                companyDB.IsDeleted = companyBO.IsDeleted.Value;
            }

            #endregion

            #region Address
            if (addressBO != null)
            {
                addressDB.id       = addressBO.ID;
                addressDB.Name     = addressBO.Name;
                addressDB.Address1 = addressBO.Address1;
                addressDB.Address2 = addressBO.Address2;
                addressDB.City     = addressBO.City;
                addressDB.State    = addressBO.State;
                addressDB.ZipCode  = addressBO.ZipCode;
                addressDB.Country  = addressBO.Country;
            }
            #endregion

            #region Contact Info

            if (contactinfoBO != null)
            {
                contactinfoDB.id           = contactinfoBO.ID;
                contactinfoDB.Name         = contactinfoBO.Name;
                contactinfoDB.CellPhone    = contactinfoBO.CellPhone;
                contactinfoDB.EmailAddress = contactinfoBO.EmailAddress;
                contactinfoDB.HomePhone    = contactinfoBO.HomePhone;
                contactinfoDB.WorkPhone    = contactinfoBO.WorkPhone;
                contactinfoDB.FaxNo        = contactinfoBO.FaxNo;
                if (contactinfoBO.IsDeleted.HasValue)
                {
                    contactinfoDB.IsDeleted = contactinfoBO.IsDeleted;
                }
            }
            #endregion

            #region User
            if (!flagUser)
            {
                userDB.UserName               = userBO.UserName;
                userDB.MiddleName             = userBO.MiddleName;
                userDB.FirstName              = userBO.FirstName;
                userDB.LastName               = userBO.LastName;
                userDB.Gender                 = System.Convert.ToByte(userBO.Gender);
                userDB.UserType               = System.Convert.ToByte(userBO.UserType);
                userDB.C2FactAuthEmailEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactEmail"));
                userDB.C2FactAuthSMSEnabled   = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactSMS"));
                userDB.ImageLink              = userBO.ImageLink;
                if (userBO.DateOfBirth.HasValue)
                {
                    userDB.DateOfBirth = userBO.DateOfBirth.Value;
                }

                if (userBO.IsDeleted.HasValue)
                {
                    userDB.IsDeleted = userBO.IsDeleted.Value;
                }

                userDB.AddressInfo       = addressDB;
                userDB.ContactInfo       = contactinfoDB;
                userCompanyDB.User       = userDB;
                userCompanyDB.IsAccepted = true;
            }
            else
            {
                //Find Record By Name
                User user_ = _context.Users.Where(p => p.UserName == userBO.UserName).FirstOrDefault <User>();
                userCompanyDB.User          = user_;
                userCompanyDB.IsAccepted    = true;
                _context.Entry(user_).State = System.Data.Entity.EntityState.Modified;
            }

            #endregion

            UserCompany cmp = new UserCompany();
            cmp.Company = companyDB;

            companyDB.AddressInfo = addressDB;
            companyDB.ContactInfo = contactinfoDB;

            if (companyDB.id > 0)
            {
                //For Update Record
            }
            else
            {
                companyDB.CreateDate     = companyBO.CreateDate;
                companyDB.CreateByUserID = companyBO.CreateByUserID;

                userDB.CreateDate     = companyBO.CreateDate;
                userDB.CreateByUserID = companyBO.CreateByUserID;

                addressDB.CreateDate     = companyBO.CreateDate;
                addressDB.CreateByUserID = companyBO.CreateByUserID;

                contactinfoDB.CreateDate     = companyBO.CreateDate;
                contactinfoDB.CreateByUserID = companyBO.CreateByUserID;

                _dbSet.Add(companyDB);
            }
            _context.SaveChanges();

            #region Insert User Block
            userCompanyDB.IsAccepted     = true;
            userCompanyDB.Company        = companyDB;
            userCompanyDB.UserStatusID   = 1; //UserStatusID = 1 --- UserStatus Pending
            userCompanyDB.CreateDate     = companyBO.CreateDate;
            userCompanyDB.CreateByUserID = companyBO.CreateByUserID;
            _dbUserCompany.Add(userCompanyDB);
            _context.SaveChanges();
            #endregion

            #region Insert User Company Role
            userCompanyRoleDB.User           = userCompanyDB.User;
            userCompanyRoleDB.RoleID         = (int)roleBO.RoleType;
            userCompanyRoleDB.CreateDate     = companyBO.CreateDate;
            userCompanyRoleDB.CreateByUserID = companyBO.CreateByUserID;
            _dbUserCompanyRole.Add(userCompanyRoleDB);
            _context.SaveChanges();
            #endregion

            #region Insert Invitation
            invitationDB.User           = userCompanyDB.User;
            invitationDB.Company        = companyDB;
            invitationDB.UniqueID       = Guid.NewGuid();
            invitationDB.CreateDate     = companyBO.CreateDate;
            invitationDB.CreateByUserID = companyBO.CreateByUserID;
            _dbInvitation.Add(invitationDB);
            _context.SaveChanges();
            #endregion

            #region Update referral
            //var referral = _context.Referrals.Where(p => p.ReferredToEmail == userDB.UserName && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).ToList<Referral>();

            //foreach (var eachReferral in referral)
            //{
            //    eachReferral.ReferredToCompanyId = companyDB.id;
            //    eachReferral.ReferralAccepted = true;
            //}

            _context.SaveChanges();
            #endregion

            BO.Company acc_ = Convert <BO.Company, Company>(companyDB);
            try
            {
                #region Send Email

                string   VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB.UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB.UniqueID + "</a>";
                string   Message          = "Dear " + userBO.FirstName + ",<br><br>Thanks for registering with us.<br><br> Your user name is:- " + userBO.UserName + "<br><br> Please confirm your account by clicking below link in order to use.<br><br><b>" + VerificationLink + "</b><br><br>Thanks";
                BO.Email objEmail         = new BO.Email {
                    ToEmail = userBO.UserName, Subject = "Company registered", Body = Message
                };
                objEmail.SendMail();
                #endregion
            }
            catch (Exception ex)
            {
                //Message sending failed
            }

            var res = (BO.GbObject)(object) acc_;
            return((object)res);
        }
示例#10
0
        public override object Save <T>(T entity)
        {
            BO.PreferredAttorneyProviderSignUp preferredAttorneyProviderBO = (BO.PreferredAttorneyProviderSignUp)(object) entity;
            PreferredAttorneyProvider          preferredMedicalProviderDB  = new PreferredAttorneyProvider();

            BO.Company  companyBO             = preferredAttorneyProviderBO.Company;
            BO.Signup   prefAttProviderBO     = preferredAttorneyProviderBO.Signup;
            Guid        invitationDB_UniqueID = Guid.NewGuid();
            User        userDB        = new User();
            UserCompany UserCompanyDB = new UserCompany();

            PreferredAttorneyProvider prefAttProvider = new PreferredAttorneyProvider();
            bool IsEditMode = false;

            IsEditMode = (preferredAttorneyProviderBO != null && preferredAttorneyProviderBO.ID > 0) ? true : false;

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                if (companyBO == null || (companyBO != null && companyBO.ID <= 0))
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (prefAttProviderBO == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (prefAttProviderBO.company == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (prefAttProviderBO.user == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                if (prefAttProviderBO.contactInfo == null)
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "No Record Found.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                //if (string.IsNullOrEmpty(prefAttProviderBO.company.TaxID) == false && _context.Companies.Any(o => o.TaxID == prefAttProviderBO.company.TaxID && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false))))
                //{
                //    dbContextTransaction.Rollback();
                //    return new BO.ErrorObject { ErrorMessage = "TaxID already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error };
                //}

                if (_context.Companies.Any(o => o.Name == prefAttProviderBO.company.Name && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false))))
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "Company already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }
                else if (_context.Users.Any(o => o.UserName == prefAttProviderBO.user.UserName && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false))))
                {
                    dbContextTransaction.Rollback();
                    return(new BO.ErrorObject {
                        ErrorMessage = "User Name already exists.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                BO.Company     prefAttProviderCompanyBO = prefAttProviderBO.company;
                BO.ContactInfo ContactInfoBO            = prefAttProviderBO.contactInfo;
                BO.User        userBO = prefAttProviderBO.user;
                BO.Role        roleBO = prefAttProviderBO.role;

                Company     prefAttProvider_CompanyDB = new Company();
                AddressInfo AddressInfo = new AddressInfo();
                ContactInfo ContactInfo = new ContactInfo()
                {
                    CellPhone = ContactInfoBO.CellPhone, EmailAddress = ContactInfoBO.EmailAddress
                };

                _context.AddressInfoes.Add(AddressInfo);
                _context.SaveChanges();

                _context.ContactInfoes.Add(ContactInfo);
                _context.SaveChanges();

                prefAttProvider_CompanyDB.Name        = prefAttProviderCompanyBO.Name;
                prefAttProvider_CompanyDB.Status      = System.Convert.ToByte(prefAttProviderCompanyBO.Status);
                prefAttProvider_CompanyDB.CompanyType = System.Convert.ToByte(prefAttProviderCompanyBO.CompanyType);

                if (prefAttProviderCompanyBO.SubsCriptionType != null)
                {
                    prefAttProvider_CompanyDB.SubscriptionPlanType = System.Convert.ToByte(prefAttProviderCompanyBO.SubsCriptionType);
                }
                else
                {
                    prefAttProvider_CompanyDB.SubscriptionPlanType = null;
                }
                prefAttProvider_CompanyDB.TaxID               = prefAttProviderCompanyBO.TaxID;
                prefAttProvider_CompanyDB.AddressId           = AddressInfo.id;
                prefAttProvider_CompanyDB.ContactInfoID       = ContactInfo.id;
                prefAttProvider_CompanyDB.BlobStorageTypeId   = 1;
                prefAttProvider_CompanyDB.CompanyStatusTypeID = 1; // CompanyStatusTypeID = 1 -- RegistrationImcomplete
                prefAttProvider_CompanyDB.IsDeleted           = prefAttProviderCompanyBO.IsDeleted;
                prefAttProvider_CompanyDB.CreateByUserID      = prefAttProviderCompanyBO.CreateByUserID;
                prefAttProvider_CompanyDB.UpdateByUserID      = prefAttProviderCompanyBO.UpdateByUserID;
                prefAttProvider_CompanyDB.CreateDate          = DateTime.UtcNow;

                _context.Companies.Add(prefAttProvider_CompanyDB);
                _context.SaveChanges();


                userDB.FirstName = userBO.FirstName;
                userDB.LastName  = userBO.LastName;
                userDB.UserName  = userBO.UserName;
                userDB.UserType  = 3;
                userDB.C2FactAuthEmailEnabled = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactEmail"));
                userDB.C2FactAuthSMSEnabled   = System.Convert.ToBoolean(Utility.GetConfigValue("Default2FactSMS"));
                userDB.AddressId      = prefAttProvider_CompanyDB.AddressId;
                userDB.ContactInfoId  = prefAttProvider_CompanyDB.ContactInfoID;
                userDB.IsDeleted      = false;
                userDB.CreateByUserID = userBO.CreateByUserID;
                userDB.CreateDate     = DateTime.UtcNow;

                _context.Users.Add(userDB);
                _context.SaveChanges();


                UserCompanyDB.UserID         = userDB.id;
                UserCompanyDB.CompanyID      = prefAttProvider_CompanyDB.id;
                UserCompanyDB.UserStatusID   = 1;
                UserCompanyDB.IsDeleted      = false;
                UserCompanyDB.CreateByUserID = 0;
                UserCompanyDB.CreateDate     = DateTime.UtcNow;
                UserCompanyDB.IsAccepted     = true;

                _context.UserCompanies.Add(UserCompanyDB);
                _context.SaveChanges();


                UserCompanyRole UserCompanyRoleDB = new UserCompanyRole();
                UserCompanyRoleDB.UserID         = userDB.id;
                UserCompanyRoleDB.RoleID         = (int)roleBO.RoleType;
                UserCompanyRoleDB.IsDeleted      = false;
                UserCompanyRoleDB.CreateDate     = DateTime.UtcNow;
                UserCompanyRoleDB.CreateByUserID = 0;

                _context.UserCompanyRoles.Add(UserCompanyRoleDB);
                _context.SaveChanges();

                prefAttProvider.PrefAttorneyProviderId = prefAttProvider_CompanyDB.id;
                prefAttProvider.CompanyId      = companyBO.ID;
                prefAttProvider.IsCreated      = true;
                prefAttProvider.IsDeleted      = false;
                prefAttProvider.CreateByUserID = prefAttProvider_CompanyDB.CreateByUserID;
                prefAttProvider.UpdateByUserID = prefAttProvider_CompanyDB.UpdateByUserID;
                prefAttProvider.CreateDate     = DateTime.UtcNow;

                _context.PreferredAttorneyProviders.Add(prefAttProvider);
                _context.SaveChanges();

                dbContextTransaction.Commit();
            }

            #region Insert Invitation
            Invitation invitationDB = new Invitation();
            invitationDB.User = userDB;

            invitationDB_UniqueID       = Guid.NewGuid();
            invitationDB.UniqueID       = invitationDB_UniqueID;
            invitationDB.CompanyID      = UserCompanyDB.CompanyID != 0 ? UserCompanyDB.CompanyID : 0;
            invitationDB.CreateDate     = DateTime.UtcNow;
            invitationDB.CreateByUserID = userDB.id;
            _context.Invitations.Add(invitationDB);
            _context.SaveChanges();
            #endregion

            if (IsEditMode == false)
            {
                try
                {
                    #region Send Email

                    var CurrentUser      = _context.Users.Where(p => p.id == prefAttProvider.CreateByUserID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <User>();
                    var CurrentCompanyId = _context.UserCompanies.Where(p => p.UserID == CurrentUser.id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.CompanyID).FirstOrDefault();
                    var CurrentCompany   = _context.Companies.Where(p => p.id == CurrentCompanyId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();

                    if (CurrentUser != null)
                    {
                        if (CurrentUser.UserType == 3)
                        {
                            var attorneyprovider_UserId = _context.UserCompanies.Where(p => p.CompanyID == prefAttProvider.PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.UserID).FirstOrDefault();
                            var attorneyprovider_user   = _context.Users.Where(p => p.id == attorneyprovider_UserId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();
                            if (attorneyprovider_user != null)
                            {
                                var PreferredAttorneyAddByAttorney = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "PreferredAttorneyAddByAttorney".ToUpper()).FirstOrDefault();
                                if (PreferredAttorneyAddByAttorney == null)
                                {
                                    return(new BO.ErrorObject {
                                        ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error
                                    });
                                }
                                else
                                {
                                    #region Send mail to attorney
                                    string VarificationLink1 = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "</a>";
                                    string msg1     = PreferredAttorneyAddByAttorney.EmailBody;
                                    string subject1 = PreferredAttorneyAddByAttorney.EmailSubject;

                                    string message1 = string.Format(msg1, attorneyprovider_user.FirstName, CurrentUser.FirstName, CurrentCompany.Name, VarificationLink1);

                                    BO.Email objEmail1 = new BO.Email {
                                        ToEmail = attorneyprovider_user.UserName, Subject = subject1, Body = message1
                                    };
                                    objEmail1.SendMail();
                                    #endregion
                                }
                            }
                        }
                        else if (CurrentUser.UserType == 2 || CurrentUser.UserType == 4)
                        {
                            var attorneyprovider_UserId = _context.UserCompanies.Where(p => p.CompanyID == prefAttProvider.PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.UserID).FirstOrDefault();
                            var attorneyprovider_user   = _context.Users.Where(p => p.id == attorneyprovider_UserId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();
                            if (attorneyprovider_user != null)
                            {
                                var PreferredAttorneyAddByProvider = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "PreferredAttorneyAddByProvider".ToUpper()).FirstOrDefault();
                                if (PreferredAttorneyAddByProvider == null)
                                {
                                    return(new BO.ErrorObject {
                                        ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error
                                    });
                                }
                                else
                                {
                                    #region Send mail to attorney
                                    string VarificationLink1 = "<a href='" + Utility.GetConfigValue("AttorneyVerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("AttorneyVerificationLink") + "/" + invitationDB_UniqueID + "</a>";
                                    string msg1     = PreferredAttorneyAddByProvider.EmailBody;
                                    string subject1 = PreferredAttorneyAddByProvider.EmailSubject;

                                    string message1 = string.Format(msg1, attorneyprovider_user.FirstName, CurrentUser.FirstName, CurrentCompany.Name, VarificationLink1);

                                    BO.Email objEmail1 = new BO.Email {
                                        ToEmail = attorneyprovider_user.UserName, Subject = subject1, Body = message1
                                    };
                                    objEmail1.SendMail();
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                }
                catch (Exception ex) { }
            }
            else
            {
                #region Send Email

                var userId = _context.UserCompanies.Where(p => p.CompanyID == prefAttProvider.PrefAttorneyProviderId && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).Select(p2 => p2.UserID).ToList();
                var userBO = _context.Users.Where(p => userId.Contains(p.id) && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault();

                if (userBO != null)
                {
                    var mailTemplateDB = _context.MailTemplates.Where(x => x.TemplateName.ToUpper() == "PrefAttorneyProviderUpdated".ToUpper()).FirstOrDefault();
                    if (mailTemplateDB == null)
                    {
                        return(new BO.ErrorObject {
                            ErrorMessage = "No record found Mail Template.", errorObject = "", ErrorLevel = ErrorLevel.Error
                        });
                    }
                    else
                    {
                        //string VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + invitationDB_UniqueID + "</a>";
                        string LoginLink2 = "<a href='http://www.patient.codearray.tk/#/account/login'>http://www.patient.codearray.tk/#/account/login </a>";
                        string msg        = mailTemplateDB.EmailBody;
                        string subject    = mailTemplateDB.EmailSubject;

                        string message = string.Format(msg, userBO.FirstName, userBO.UserName, LoginLink2);

                        BO.Email objEmail = new BO.Email {
                            ToEmail = userBO.UserName, Subject = subject, Body = message
                        };
                        objEmail.SendMail();
                    }
                }
                #endregion
            }
            var result = _context.PreferredAttorneyProviders.Include("Company").Include("Company1")
                         .Where(p => p.Id == prefAttProvider.Id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false)))
                         .FirstOrDefault();

            BO.PreferredAttorneyProvider acc_ = Convert <BO.PreferredAttorneyProvider, PreferredAttorneyProvider>(result);

            var res = (BO.GbObject)(object) acc_;
            return((object)res);
        }
示例#11
0
文件: User.cs 项目: Bubelks/Bubelsoft
 public User(string firstName, string lastName, UserCompanyRole companyRole, string email)
 {
     Update(firstName, lastName, email);
     CompanyRole = companyRole;
     Roles       = new List <UserRole>();
 }
示例#12
0
文件: User.cs 项目: Bubelks/Bubelsoft
 public User(UserId id, string firstName, string lastName, UserCompanyRole companyRole, string email)
     : this(firstName, lastName, companyRole, email)
 {
     Id = id;
 }