예제 #1
0
		public void SaveBranche(BrancheViewModel brancheViewModel, string companyId)
		{
			var company = _clientCompanyManagement.FindById(companyId);

			if (company != null)
			{
				var isNew = brancheViewModel.IsNew;

				if (isNew)
				{
					var branch = new ClientCompanyBranche();
					brancheViewModel.FillModel(branch);
					company.Branches.Add(branch);
				}
				else
				{
					int brancheId;
					Int32.TryParse(brancheViewModel.Id, out brancheId);
					var companyBranch = company.Branches.FirstOrDefault(e => e.Id == brancheId);

					ChangeUserStatusDependingOnBranchStatus(brancheId, brancheViewModel.Status);

					if (companyBranch != null)
					{
						brancheViewModel.FillModel(companyBranch);
					}

				}
			}
		}
예제 #2
0
		public ClientUserViewModel(ClientUser clientUser, string companyState = null, string branchState = null)
		{
			User = new UserViewModel();
			User.Email = clientUser.User.Email;
			User.FirstName = clientUser.User.FirstName;
			User.LastName = clientUser.User.LastName;
			RoleType = clientUser.User.PrimaryRole.RoleType;
			Status = clientUser.Status;
			PhoneNumber = clientUser.PhoneNumber;
			IsViewAllCompanyOrders = clientUser.IsViewAllCompanyOrders;
			IsUserLocked = clientUser.IsUserLocked;

			if (clientUser.Company != null)
			{
				Company = new ClientCompanyViewModel(clientUser.Company, companyState);
				CompanyName = clientUser.Company.CompanyName;
				CompanyID = clientUser.Company.Id;

				if (clientUser.Branch != null)
				{
					Branch = new BrancheViewModel(clientUser.Branch, clientUser.Company.Status, branchState, false, null);
					BranchID = clientUser.Branch.Id;
				}
			}
		}
예제 #3
0
    public ActionResult SaveBranche(BrancheViewModel brancheViewModel, string companyId, bool isRedirect = false)
    {
      var isNew = string.IsNullOrEmpty(brancheViewModel.Id);
      if (ModelState.IsValid)
      {
        _branchesService.SaveBranche(brancheViewModel, companyId);
        CommitProviderInstance.Commit();

        if (isRedirect)
        {
          TempData["Message"] = isNew ? NewBranchMessage : UpdateBranchMessage;
          return RedirectToAction(
            NameHelper.ClientCompaniesManagement.Branches.Index,
            NameHelper.ClientCompaniesManagement.Branches.Controller,
            new { area = NameHelper.ClientCompaniesManagement.Area, companyId = companyId });
        }
        else
        {
          TempData["Count"] = brancheViewModel.Count;
          return RedirectToAction(
            NameHelper.ClientCompaniesManagement.Branches.ClientBranchDetails,
            NameHelper.ClientCompaniesManagement.Branches.Controller,
            new { area = NameHelper.ClientCompaniesManagement.Area, companyId = companyId });
        }
      }

      ModelState.Clear();

      TempData[_clientBranchKey] = brancheViewModel;

      return RedirectToAction(NameHelper.ClientCompaniesManagement.Branches.ClientBranchDetails, brancheViewModel);
    }
예제 #4
0
		public void SaveBranche_should_save_if_branch_is_new()
		{
			var companyId = "companyId";
			var model = new BrancheViewModel
			{
				IsNew = true,
				Address = new AddressViewModel()
			};
			var branch = new ClientCompanyBranche
			{
				Name = "Branch",
				StatusId = Enum.GetName(typeof(ClientCompanyBrancheStatus), ClientCompanyBrancheStatus.Active),
				Address = new Address()
			};
			var branches = new[] { branch }.ToList();
			var company = new ClientCompany { Branches = branches };
			var companies = new[] { company };
			_clientCompanyManagement.GetCompanies(Arg.Any<Func<IQueryable<ClientCompany>, IQueryable<ClientCompany>>>()).ReturnsForAnyArgs(companies);

			_target.SaveBranche(model, companyId);
		}
예제 #5
0
		public BrancheViewModel GetBranche(string companyId, string branchId)
		{
			var company = _clientCompanyManagement.FindById(companyId);
			var result = new BrancheViewModel { Address = new AddressViewModel(), IsNew = true };

			if (company != null)
			{
				int branchIntId;
				Int32.TryParse(branchId, out branchIntId);

				var companyBranch = company.Branches.FirstOrDefault(c => c.Id == branchIntId);

				if (companyBranch != null)
				{
					var clienCompanyStatusBuilder = new ClientCompanyStatusBuilder(company);

					result = new BrancheViewModel(companyBranch, company.Status, _referenceManagement.FindState(companyBranch.Address.State), clienCompanyStatusBuilder.AllowEditBrancheStatus(), _statusHistoryManager.GetClientCompanyBranchStatusHistory(branchIntId));
				}
			}

			return result;
		}
예제 #6
0
		public BrancheStatusViewModel(BrancheViewModel brancheViewModel)
		{
			if (brancheViewModel != null)
			{
				Status = brancheViewModel.Status;
				BrancheId = brancheViewModel.Id;
				CompanyStatus = brancheViewModel.CompanyStatus;
				_allowEditStatus = brancheViewModel.AllowEditStatus;
			}
		}
예제 #7
0
    public ActionResult SaveBrancheAndAdd(BrancheViewModel brancheViewModel)
    {
      if (ModelState.IsValid)
      {
        _branchesService.SaveBranche(brancheViewModel, PluginResults.Find<UserAccessPluginResult>().CompnayId);
        CommitProviderInstance.Commit();
      }

      ModelState.Clear();
      return ShowAddDialog();
    }