/// <summary>
        /// CreatedBy: Kanishka
        /// CreatedDate:2016/1/18
        /// insert first branch details
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateBranchFirstBranch()
        {
            var type = (string)Session["type"];

            if (type == "CompanyEmployee")
            {
                ViewBag.Type = "CompanyEmployee";
                _type        = "CompanyEmployee";

                if (TempData["UserCompany"] == null)
                {
                    return(RedirectToAction("EmployeeLogin", "Login"));
                }

                CompanyAccess ca = new CompanyAccess();
                //Get states to list
                List <State> stateList = ca.GetAllStates();
                ViewBag.StateId = new SelectList(stateList, "StateId", "StateName");

                _userCompany        = (UserCompanyModel)TempData["UserCompany"];
                _userCompany.Branch = new Branch();

                return(View(_userCompany));
            }
            else
            {
                ViewBag.Type = "";
                return(RedirectToAction("EmployeeLogin", "Login"));
            }
        }
Esempio n. 2
0
        public ActionResult Setup(Company company)
        {
            if (Session["type"] == null)
            {
                return(RedirectToAction("UserLogin", "Login"));
            }

            //if (type == "CompanyEmployee")
            //{

            //}

            GeneratesCode gc = new GeneratesCode();

            company.CompanyCode = gc.GenerateCompanyCode(company.CompanyName);

            UserCompanyModel userCom = new UserCompanyModel();

            userCom.User = _user;

            company.Zip = company.ZipPre;
            if (company.Extension != null)
            {
                company.Zip += "-" + company.Extension;
            }

            userCom.Company = company;

            TempData["UserCompany"] = userCom;
            return(RedirectToAction("CreateBranchFirstBranch", "CreateBranch", new { id = 0, type = "CompanyEmployee" }));
        }
        public ObjectResult CreateUser(UserCompanyModel userCompany, CancellationToken cancellationToken = default)
        {
            var isUserCompanyExist = _unitOfWork.GetRepository <UserCompanyModel>().IsExist(
                userCompanyModel => userCompanyModel.Email == userCompany.Email);

            if (isUserCompanyExist)
            {
                var badResult = BadRequestObjectResultFactory.Create(
                    nameof(userCompany.Email),
                    "Company with provided email already exist");
                return(badResult);
            }

            userCompany = _unitOfWork.GetRepository <UserCompanyModel>().Create(userCompany);
            _unitOfWork.Save();
            var userCompanyViewModel = _mapper.Map <UserCompanyViewModel>(userCompany);

            var result = new OkObjectResult(userCompanyViewModel);

            return(result);
        }
 public ActionResult CreateBranchFirstBranch(UserCompanyModel userCompany)
 {
     if (_type == "CompanyEmployee")
     {
         ViewBag.Type = "CompanyEmployee";
         BranchAccess ba = new BranchAccess();
         userCompany.Branch.BranchCode = ba.createBranchCode(_userCompany.Company.CompanyCode);
         _userCompany.Branch           = userCompany.Branch;
         _userCompany.Branch.StateId   = userCompany.StateId;
         CompanyAccess ca = new CompanyAccess();
         //if (ca.SetupCompany(_userCompany))
         if (ca.SetupCompanyRollback(_userCompany))
         {
             ViewBag.SuccessMsg = "Company is successfully setup";
             return(View());
         }
         else
         {
             ViewBag.ErrorMsg = "Failed to setup company";
             return(RedirectToAction("CreateFirstSuperUser", "CreateUser"));
         }
     }
     return(View());
 }