public long CreateFranchisee(FranchiseeEditModel model) { var organizationId = Create(model); if (model.AllocatedPods != null) { var podRepository = new PodRepository(); podRepository.AssignGivenPodstoaFranchisee(model.AllocatedPods.Select(pod => pod.Id).ToArray(), organizationId); } return(organizationId); }
public FranchiseeEditModel GetFranchiseeCreateModel(long id) { var franchiseeModel = new FranchiseeEditModel(); AddressEditModel billingAddress, businessAddress; File teamImage, logoImage; Organization organization = GetDomainforOrganizationCreateModel(id, out billingAddress, out businessAddress, out teamImage, out logoImage); var binder = new OrganizationCreateModelBinder(); franchiseeModel = binder.ToModel(franchiseeModel, organization, billingAddress, businessAddress, logoImage, teamImage) as FranchiseeEditModel; var podReposirotry = new PodRepository(); var pods = podReposirotry.GetPodsAssignedToFranchisee(id); if (pods != null && pods.Count > 0) { franchiseeModel.AllocatedPods = pods.ToArray(); } return(franchiseeModel); }
private FranchiseeEditModel SetFranchiseeData(FranchiseeEditModel franchiseeEditModel) { if (franchiseeEditModel == null) { franchiseeEditModel = new FranchiseeEditModel(); } franchiseeEditModel.Name = txtFranchiseeName.Text; franchiseeEditModel.Description = txtDesciption.Text; var address = new AddressEditModel(); address.StreetAddressLine1 = txtbuaddress1.Text; address.StreetAddressLine2 = txtbuaddress2.Text; address.CountryId = _countryId; if (ddlBuState.SelectedIndex > 0) { address.StateId = Convert.ToInt32(ddlBuState.SelectedItem.Value); } address.City = txtBuCity.Text; if (!string.IsNullOrEmpty(txtBuZip.Text)) { address.ZipCode = txtBuZip.Text; } if (!address.IsEmpty()) { if (franchiseeEditModel.BusinessAddress != null) { address.Id = franchiseeEditModel.BusinessAddress.Id; } franchiseeEditModel.BusinessAddress = address; } else { franchiseeEditModel.BusinessAddress = null; } if (!chkBiAddress.Checked) { address = new AddressEditModel(); address.StreetAddressLine1 = txtBiAddress1.Text; address.StreetAddressLine2 = txtBiAddress2.Text; address.CountryId = _countryId; if (ddlBiState.SelectedIndex > 0) { address.StateId = Convert.ToInt32(ddlBiState.SelectedItem.Value); } address.City = txtBiCity.Text; if (!string.IsNullOrEmpty(txtBiZip.Text)) { address.ZipCode = txtBiZip.Text; } if (!address.IsEmpty()) { if (franchiseeEditModel.BillingAddress != null) { address.Id = franchiseeEditModel.BillingAddress.Id; } franchiseeEditModel.BillingAddress = address; } else { franchiseeEditModel.BillingAddress = null; } } else { address.Id = 0; if (franchiseeEditModel.BillingAddress != null) { address.Id = franchiseeEditModel.BillingAddress.Id; } franchiseeEditModel.BillingAddress = address; } franchiseeEditModel.FaxNumber = new PhoneNumber() { Number = txtBuFax.Text }; franchiseeEditModel.PhoneNumber = new PhoneNumber() { Number = txtBuPhone.Text }; var pods = new List <Pod>(); foreach (ListItem item in PodCheckboxList.Items) { pods.Add(new Pod(Convert.ToInt64(item.Value))); } franchiseeEditModel.AllocatedPods = pods.ToArray(); return(franchiseeEditModel); }
private bool SaveData() { var organziationService = IoC.Resolve <IOrganizationService>(); var userService = IoC.Resolve <IUserService>(); var countryRepository = IoC.Resolve <ICountryRepository>(); _countryId = countryRepository.GetAll().FirstOrDefault().Id; FranchiseeEditModel franchiseeEditModel = null; User user = null; if (FranchiseeId > 0) { franchiseeEditModel = organziationService.GetFranchiseeCreateModel(FranchiseeId); user = userService.GetDefaultUserforOrganization(FranchiseeId, OrganizationType.Franchisee); } var userRepository = IoC.Resolve <IUserRepository <User> >(); if (user == null || user.Email.ToString() != UCAddress1.Email) { if (!userRepository.UniqueEmail(UCAddress1.Email)) { divErrorMsg.Visible = true; divErrorMsg.InnerText = "Contact email already exists. Please try another email."; return(false); } } franchiseeEditModel = SetFranchiseeData(franchiseeEditModel); user = SetDefaulUserData(user); if (FranchiseeId == 0 && userRepository.UserNameExists(LoginIdTextbox.Text)) { divErrorMsg.Visible = true; divErrorMsg.InnerText = "Please specify a unique user name."; return(false); } if (franchiseeEditModel == null || user == null) { return(false); } try { using (var scope = new TransactionScope()) { var organizationId = organziationService.CreateFranchisee(franchiseeEditModel); userService.SaveDefaultUserforOrganization(organizationId, OrganizationType.Franchisee, user); scope.Complete(); return(true); } } catch (InvalidAddressException ex) { divErrorMsg.Visible = true; divErrorMsg.InnerText = "Invalid Address Exception. Exception Message : " + ex.Message; return(false); } catch (Exception ex) { divErrorMsg.Visible = true; divErrorMsg.InnerText = "Some database error occured. Exception Message : " + ex.Message; return(false); } }