Example #1
0
        public static Companies UpdateCompany(HttpServerUtilityBase server, HttpFileCollectionBase files, EditCompanyModel changes)
        {
            CustomizeCompany customize = new CustomizeCompany
            {
                StartVideo             = changes.startVideo ?? "",
                LogoUrl                = changes.logoUrl ?? "",
                LoginLogoUrl           = changes.loginLogoUrl ?? "",
                MenuActiveColor        = changes.menuActiveColor ?? "",
                MenuPassiveColor       = changes.menuPassiveColor ?? "",
                HeaderColor            = changes.headerColor ?? "",
                ButtonsBackgroundColor = changes.buttonsBackgroundColor ?? "",
                ButtonsActiveColor     = changes.buttonsActiveColor ?? ""
            };

            CompanyHelper.SaveFiles(server, files, changes.companyName, customize);

            string json = JsonConvert.SerializeObject(customize);

            return(companyRepo.UpdateCompany(changes, json));
        }
Example #2
0
        public static Companies AddCompany(HttpServerUtilityBase Server, HttpFileCollectionBase httpFileCollectionBase, EditCompanyModel model)
        {
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            UserManager.UserValidator = new UserValidator <ApplicationUser>(UserManager)
            {
                AllowOnlyAlphanumericUserNames = false
            };

            Companies        tmp       = model.Companies;
            CustomizeCompany customize = new CustomizeCompany
            {
                StartVideo             = model.startVideo ?? "",
                LogoUrl                = model.logoUrl ?? "",
                LoginLogoUrl           = model.loginLogoUrl ?? "",
                MenuActiveColor        = model.menuActiveColor ?? "",
                MenuPassiveColor       = model.menuPassiveColor ?? "",
                HeaderColor            = model.headerColor ?? "",
                ButtonsBackgroundColor = model.buttonsBackgroundColor ?? "",
                ButtonsActiveColor     = model.buttonsActiveColor ?? ""
            };

            CompanyHelper.SaveFiles(Server, httpFileCollectionBase, model.companyName, customize);
            string pswd = CommonHelper.UserKey();

            tmp.CustomizeCompany = JsonConvert.SerializeObject(customize);
            tmp.TempPassword     = pswd;
            tmp.Speech           = model.speech;
            tmp.Lang             = model.lang;
            tmp.CompanyStatus    = (int)Status.NewlyCreated;
            tmp.Created          = DateTime.Now;
            companyRepo.AddCompany(tmp);

            var department = new NewDB.Departments();

            department.CompanyId      = tmp.Id;
            department.DepartmentName = CompanyHelper.InnitialDepartment;
            department = companyRepo.AddNewDepartment(department);
            //var userName = tmp.Name.Replace(" ", "_");

            var userName = tmp.ContactName + "_" + tmp.ContactSurname;
            var user     = new ApplicationUser()
            {
                UserName = userName
            };
            var result = UserManager.Create(user, pswd);

            if (result.Succeeded)
            {
                UserManager.AddToRole(user.Id, "User");
                UserManager.AddToRole(user.Id, "Manager");
                UserManager.AddToRole(user.Id, "Administrator");
                var userProfile = new UserProfiles
                {
                    CompanyId    = tmp.Id,
                    Email        = tmp.Email,
                    Firstname    = tmp.ContactName,
                    Lastname     = tmp.ContactSurname,
                    Phone        = tmp.ContactPhone,
                    AspNetUserId = user.Id,
                    DepartmentId = department.Id,
                    UserKey      = CommonHelper.UserKey(),
                    Lang         = 3,
                    Speech       = 3
                };
                userProfile = UserService.AddUser(userProfile);
                //do not remove. It's magic spell, that makes entity work correctly
                userProfile.AspNetUsers = new AspNetUsers {
                    UserName = user.UserName, Id = user.Id
                };
                tmp.AdminId = userProfile.Id;
            }
            return(tmp);
        }