public TerritoryRegion GetTerritoryRegion(Guid UserGUID) { TerritoryRegion lTerritoryRegion = new TerritoryRegion(); ITerritoryRepository _ITerritoryRepository = new TerritoryRepository(new WorkersInMotionDB()); IRegionRepository _IRegionRepository = new RegionRepository(new WorkersInMotionDB()); IOrganizationRepository _IOrganizationRepository = new OrganizationRepository(new WorkersInMotionDB()); Guid OrganizationGUID = _IOrganizationRepository.GetOrganizationIDByUserGUID(UserGUID); List <Territory> TerritoryList = _ITerritoryRepository.GetTerritoryByOrganizationGUID(OrganizationGUID).ToList(); if (TerritoryList != null && TerritoryList.Count > 0) { lTerritoryRegion.Territories = new List <MobileTerritory>(); foreach (Territory item in TerritoryList) { MobileTerritory lterritory = new MobileTerritory(); lterritory = convertTerritoryToMobileTerritory(item); lTerritoryRegion.Territories.Add(lterritory); } } List <Region> RegionList = _IRegionRepository.GetRegionByOrganizationGUID(OrganizationGUID).ToList(); if (RegionList != null && RegionList.Count > 0) { lTerritoryRegion.Regions = new List <MobileRegion>(); foreach (Region item in RegionList) { MobileRegion lregion = convertRegionToMobileRegion(item); lTerritoryRegion.Regions.Add(lregion); } } return(lTerritoryRegion); }
public IEnumerable <ModelValidationResult> Validate(ModelValidationContext context) { IEnumerable <ModelValidationResult> result = Enumerable.Empty <ModelValidationResult>(); // Dependancy injection does not work with attributes so manually wire up the database context. using (NorthwindContext dbContext = DAL.Startup.NorthwindContext) { IRepository <Territory, string> territories = new TerritoryRepository(dbContext); string value = context.Model as string; if (value == null) { result = new List <ModelValidationResult>() { new ModelValidationResult("", "A territory id must be provided") }; } else { Territory territory = territories.Fetch(value); if (territory == null) { result = new List <ModelValidationResult>() { new ModelValidationResult("", ErrorMessage) }; } } } return(result); }
// // GET: /Territory/Delete/5 public ActionResult Delete(int id) { IRepository <Models.Territory> repo = new TerritoryRepository(); repo.Delete(repo.GetById(id)); return(RedirectToAction("Index")); }
// // GET: /Territory/Edit/5 public ActionResult Edit(int id) { IRepository <Territory> repo = new TerritoryRepository(); ViewBag.Regions = RegionRepository.GetAllForTerritory(); return(View(repo.GetById(id))); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here IRepository <Models.Territory> repo = new TerritoryRepository(); repo.Delete(repo.GetById(id)); return(RedirectToAction("Index")); } catch { return(View()); } }
public void Get_ListEmployee_Territory() { TerritoryRepository repoTerritory = new TerritoryRepository(); Territory territoryNew = new Territory() { TerritoryDescription = "territoty 1", Employees = new List <Employee>() { new Employee() { FirstName = "Name 1", LastName = "LastaName 1", Localization = new Address() { Street = "Street 1", City = "City 1", Country = "Country 1" }, EmployeeExt = new EmployeeExtended() { Notes = "xx xx xx xx" } }, new Employee() { FirstName = "Name 2", LastName = "LastaName 2" } } }; repoTerritory.Create(territoryNew); var territorySel = repoTerritory.Single(x => x.TerritoryId == territoryNew.TerritoryId, new List <Expression <Func <Territory, object> > >() { x => x.Employees }); Assert.IsNotNull(territorySel); Assert.IsNotNull(territorySel.Employees); Assert.AreEqual(territorySel.Employees.Count, 2); }
public LookUpService() { _custClassRepo = new CustClassRepository(context); _paymentTermsRepo = new PaymentTermsRepository(context); _statementCycleRepository = new StatementCycleRepository(context); _shipMethodRepository = new ShipMethodRepository(context); _businessFormRepository = new BusinessFormRepository(context); _salesSourceRepository = new SalesSourceRepository(context); _branchRepository = new BranchRepository(context); _salesTerritoryRepository = new SalesTerritoryRepository(context); _territoryRepository = new TerritoryRepository(context); _countryRepository = new CountryRepository(context); _customerRepository = new CustomerRepository(context); _userRepository = new UserRepository(context); _groupRepository = new GroupRepository(context); _creditCardTypeRepository = new CreditCardTypeRepository(context); _stateRepository = new StateRepository(context); _taxSubjClassRepository = new TaxSubjClassRepository(context); _taxScheduleRepository = new TaxScheduleRepository(context); _batchRepository = new BatchRepository(); }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here string name = collection.Get("Name"); Territory Territory = new Territory() { Name = name }; string param_regions; string[] arrayRegions; if (collection.Get("Regions") != null) { param_regions = collection.Get("Regions");; arrayRegions = param_regions.Split(','); foreach (string str in arrayRegions) { int RegionID = Convert.ToInt32(str); Region region = new Region(); IRepository <Region> repo_region = new RegionRepository(); region = repo_region.GetById(RegionID); Territory.Regions.Add(region); } } IRepository <Territory> repo = new TerritoryRepository(); repo.Save(Territory); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, FormCollection collection) { try { string name = collection.Get("Name"); Territory Territory = new Territory(); IRepository <Territory> repo = new TerritoryRepository(); Territory = repo.GetById(id); Territory.ClearRegions(); Territory.Name = name; string param_regions; string[] arrayRegions; if (collection.Get("Regions") != null) { param_regions = collection.Get("Regions");; arrayRegions = param_regions.Split(','); foreach (string str in arrayRegions) { int RegionID = Convert.ToInt32(str); Region region = new Region(); IRepository <Region> repo_region = new RegionRepository(); region = repo_region.GetById(RegionID); Territory.Regions.Add(region); } } repo.Update(Territory); return(RedirectToAction("Index")); } catch { return(View()); } }
private DataTable GetEventData(DateTime startDate, DateTime endDate, string strOwner) { var masterDal = new MasterDAL(); List <EEvent> eventForCalendar = masterDal.GetEventForCalendar(SalesRepId, startDate.ToShortDateString(), endDate.ToShortDateString(), 0, HostName, FranchiseeId, PodIds, TerritoryIds); if (!string.IsNullOrEmpty(TerritoryIds)) { var territoryIds = new List <long>(); TerritoryIds.Split(',').ToList().ForEach(territoryId => territoryIds.Add(Convert.ToInt64(territoryId))); ITerritoryRepository territoryRepository = new TerritoryRepository(); List <Territory> territories = territoryRepository.GetTerritories(territoryIds); List <string> territoryZipCodes = territories.SelectMany(territory => territory.ZipCodes.Select(zipCode => zipCode.Zip)).ToList(); eventForCalendar = eventForCalendar.Where(eventData => territoryZipCodes.Contains(eventData.Host.Address.Zip)).ToList(); } if (eventForCalendar != null) { for (int count = 0; count < eventForCalendar.Count; count++) { string strEventDescription = ""; string eventData = "\"" + eventForCalendar[count].Name.Replace("'", "").Replace("\n", "") + " \""; string eventStatus = "\"" + Convert.ToString(Enum.Parse(typeof(EventStatus), eventForCalendar[count].EventStatus.ToString())).Replace("\n", "").Replace("'", "") + " \""; string currentEventDate = "\"" + Convert.ToDateTime(eventForCalendar[count].EventDate).ToLongDateString() + " \""; string eventStartTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventStartTime).ToShortTimeString() + " \""; string eventEndTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventEndTime).ToShortTimeString() + " \""; string timeZone = "\"" + eventForCalendar[count].TimeZone + " \""; string address1 = "\"" + eventForCalendar[count].Host.Address.Address1.Replace("\n", "").Replace("'", "") + " \""; string address2 = "\"" + eventForCalendar[count].Host.Address.Address2.Replace("\n", "").Replace("'", "") + " \""; string city = "\"" + eventForCalendar[count].Host.Address.City + " \""; string state = "\"" + eventForCalendar[count].Host.Address.State + " \""; string country = "\"" + eventForCalendar[count].Host.Address.Country + " \""; string zip = "\"" + eventForCalendar[count].Host.Address.Zip + " \""; string franchisee = "\"" + eventForCalendar[count].Franchisee.Name.Replace("\n", "").Replace("'", "") + " \""; string salesRep = "\"" + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.FirstName + " " + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.LastName + " \""; string controlID = "\"Event" + eventForCalendar[count].EventID + strOwner + "\""; string customerCount; TimeSpan dateDifference = Convert.ToDateTime(eventForCalendar[count].EventDate).Subtract(DateTime.Now); int days = dateDifference.Days; if (days < 0) { customerCount = "\" Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | Cancel:" + eventForCalendar[count].CancelCustomersCount + " \""; } else if (days == 0) { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | On Site :" + eventForCalendar[count].OnSiteCustomersCount + " \""; } else { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Paid:" + eventForCalendar[count].PaidCustomersCount + " | UnPaid :" + eventForCalendar[count].UnpaidCustomersCount + " |Cancel :" + eventForCalendar[count].CancelCustomersCount + " \""; } strEventDescription = eventData + "," + eventStatus + "," + currentEventDate + "," + eventStartTime + "," + eventEndTime + "," + timeZone + "," + customerCount + "," + address1.Trim() + "," + address2 + "," + city + "," + state + "," + country + "," + zip + "," + franchisee + "," + salesRep + "," + controlID; string strEventView = string.Empty; strEventView = "onclick = 'window.location=\"EventDetails.aspx?EventID=" + eventForCalendar[count].EventID.ToString() + "\"'"; string strAddress = CommonCode.AddressMultiLine(eventForCalendar[count].Host.Address.Address1, eventForCalendar[count].Host.Address.Address2, eventForCalendar[count].Host.Address.City, eventForCalendar[count].Host.Address.State, eventForCalendar[count].Host.Address.Zip); string podName = string.Empty; var jTipData = "Event Details for " + eventData.Replace("\"", string.Empty) + "[" + eventForCalendar[count].EventID + "] " + "<span class=\"whitetxt12\">(" + eventStatus.Replace("\"", string.Empty).Trim() + ")</span>" + "|<p class=\"jtprowtop \"><span class=\"lbljtip\">Date & Time:</span>" + "<span class=\"dtlsjtip\">" + currentEventDate.Replace("\"", string.Empty) + "<br />" + eventStartTime.Replace("\"", string.Empty) + "–" + eventEndTime.Replace("\"", string.Empty) + "<br />" + timeZone.Replace("\"", string.Empty) + "</span>" + "</p><p class=\"jtprow\"><span class=\"lbljtip\"> Address: </span>" + "<span class=\"dtlsjtip\">" + strAddress.Replace("\"", string.Empty) + "</span></p><p class=\"jtprow\"><span class=\"lbljtip\"> Owner: </span>" + "<span class=\"dtlsjtip\">" + salesRep.Replace("\"", string.Empty) + "<br />(" + franchisee.Replace("\"", string.Empty) + ")" + "</span></p>"; podName = "<p class=\"jtprow\"><span class=\"lbljtip\"> Pod Name: </span>"; podName = podName + "<span class=\"dtlsjtip\">"; if (eventForCalendar[count].EventPod != null) { for (int podcount = 0; podcount < eventForCalendar[count].EventPod.Count; podcount++) { podName = podName + eventForCalendar[count].EventPod[podcount].Pod.Name.Replace("\"", string.Empty) + "<br />"; } } podName = podName + "</span></p>"; jTipData = jTipData + podName + "<p class=\"jtprow\"><span class=\"lbljtip\"> Statistics/Health: </span> </p>" + "<p class=\"jtprowtop\"><span class=\"custcauntjtp\"><span class=\"ttxt\"> Registered Customers </span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].RegisteredCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Attended Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].AttendedCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Canceled Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].CancelCustomersCount.ToString().Replace("\"", string.Empty) + "</span></span></p>"; string strEventName = "<a class='jtip' title='" + jTipData + "'" + strEventView + " ><img src='../Images/addevent-square.gif' height='14px' width='14px' /><span class='celltxt_clnder'> </span></a>"; _tblAppointments.Rows.Add(new object[] { "Event" + eventForCalendar[count].EventID.ToString() + strOwner, "Event", strEventName, eventForCalendar[count].EventDate, strEventDescription }); } } FillBlockedDays(startDate, endDate, strOwner); return(_tblAppointments); }
public TerritoryController(TerritoryRepository territoryRepository) { this._territoryRepository = territoryRepository; }
private void GetEventDataByDate(DateTime startDate, DateTime endDate) { List <EEvent> eventForCalendar; if (IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole.CheckRole((long)Roles.SalesRep)) { eventForCalendar = _masterDal.GetEventForCalendar(0, startDate.ToShortDateString(), endDate.ToShortDateString(), 0, HostName, FranchiseeId, PodIds, TerritoryIds); } else { eventForCalendar = _masterDal.GetEventForCalendar(SalesRepId, startDate.ToShortDateString(), endDate.ToShortDateString(), 0, HostName, FranchiseeId, PodIds, TerritoryIds); } var eventIds = new List <long>(); ITerritoryRepository territoryRepository = new TerritoryRepository(); if (!string.IsNullOrEmpty(TerritoryIds) && TerritoryIds != "0") { var territoryIds = TerritoryIds.Split(',').ToList().Select(ti => Convert.ToInt64(ti)).ToList(); List <Territory> territories = territoryRepository.GetTerritories(territoryIds); List <string> territoryZipCodes = territories.SelectMany(territory => territory.ZipCodes.Select(zipCode => zipCode.Zip)).ToList(); eventForCalendar = eventForCalendar.Where(eventData => territoryZipCodes.Contains(eventData.Host.Address.Zip)).ToList(); if (SalesRepId > 0) { var salesRepTerritories = territoryRepository.GetTerritoriesForSalesRep(SalesRepId).Where(t => territoryIds.Contains(t.Id)) .ToList(); foreach (var calenderEvent in eventForCalendar) { var @event = calenderEvent; var filteredSalesRepTerritories = salesRepTerritories.Where( st => st.ZipCodes.Select(z => z.Zip).Contains(@event.Host.Address.Zip)); foreach (var filteredSalesRepTerritory in filteredSalesRepTerritories) { SalesRepTerritory territory = filteredSalesRepTerritory; if (filteredSalesRepTerritories.All(fstpt => fstpt.ParentTerritoryId != territory.Id)) { var territoryAssignment = territory.SalesRepTerritoryAssignments.SingleOrDefault(srta => srta.SalesRep.SalesRepresentativeId == SalesRepId); if (territoryAssignment != null && (int)territoryAssignment.EventTypeSetupPermission != 0 && calenderEvent.EventType.EventTypeID != (int)territoryAssignment.EventTypeSetupPermission) { eventIds.Add(@event.EventID); } } } } } } if (eventForCalendar != null) { for (int count = 0; count < eventForCalendar.Count; count++) { string eventData = "\"" + eventForCalendar[count].Name.Replace("\n", "").Replace("'", "") + " \""; string eventStatus = "\"" + Convert.ToString(Enum.Parse(typeof(EventStatus), eventForCalendar[count].EventStatus.ToString())).Replace("\n", "").Replace("'", "") + " \""; string eventDate = "\"" + Convert.ToDateTime(eventForCalendar[count].EventDate).ToLongDateString() + " \""; string eventStartTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventStartTime).ToShortTimeString() + " \""; string eventEndTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventEndTime).ToShortTimeString() + " \""; string timeZone = "\"" + eventForCalendar[count].TimeZone + " \""; string address1 = "\"" + eventForCalendar[count].Host.Address.Address1.Replace("\n", "").Replace("'", "") + " \""; string address2 = "\"" + eventForCalendar[count].Host.Address.Address2.Replace("\n", "").Replace("'", "") + " \""; string city = "\"" + eventForCalendar[count].Host.Address.City + " \""; string state = "\"" + eventForCalendar[count].Host.Address.State + " \""; string country = "\"" + eventForCalendar[count].Host.Address.Country + " \""; string zip = "\"" + eventForCalendar[count].Host.Address.Zip + " \""; string franchisee = "\"" + eventForCalendar[count].Franchisee.Name.Replace("\n", "").Replace("'", "") + " \""; string salesRep = "\"" + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.FirstName + " " + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.LastName + " \""; string controlId = "\"Event" + eventForCalendar[count].EventID + "\""; string customerCount; TimeSpan dateDifference = Convert.ToDateTime(eventForCalendar[count].EventDate).Subtract(DateTime.Now); int days = dateDifference.Days; if (days < 0) { customerCount = "\" Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | Cancel:" + eventForCalendar[count].CancelCustomersCount + " \""; } else if (days == 0) { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | On Site :" + eventForCalendar[count].OnSiteCustomersCount + " \""; } else { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Paid:" + eventForCalendar[count].PaidCustomersCount + " | UnPaid :" + eventForCalendar[count].UnpaidCustomersCount + " |Cancel :" + eventForCalendar[count].CancelCustomersCount + " \""; } string strAddress = CommonCode.AddressMultiLine(eventForCalendar[count].Host.Address.Address1, eventForCalendar[count].Host.Address.Address2, eventForCalendar[count].Host.Address.City, eventForCalendar[count].Host.Address.State, eventForCalendar[count].Host.Address.Zip); strAddress = "\"" + strAddress.Replace("\n", "").Replace("'", "") + " \""; string strEventDescription = eventData + "," + eventStatus + "," + eventDate + "," + eventStartTime + "," + eventEndTime + "," + timeZone + "," + customerCount + "," + strAddress.Trim() + "," + address2 + "," + city + "," + state + "," + country + "," + zip + "," + franchisee + "," + salesRep + "," + controlId; string strEventView = string.Empty; if (!eventIds.Contains(eventForCalendar[count].EventID)) { strEventView = "onclick = 'window.location=\"EventDetails.aspx?EventID=" + eventForCalendar[count].EventID.ToString() + "\"'"; } //} string salesRepInitials = eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.FirstName.Substring(0, 1) + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.LastName.Substring(0, 1); string podName = string.Empty; var jTipData = "Event Details for " + eventData.Replace("\"", string.Empty) + "[" + eventForCalendar[count].EventID + "] " + "<span class=\"whitetxt12\">(" + eventStatus.Replace("\"", string.Empty).Trim() + ")</span>" + "|<p class=\"jtprowtop \"><span class=\"lbljtip\"> Date & Time: </span>" + "<span class=\"dtlsjtip\">" + eventDate.Replace("\"", string.Empty) + "<br />" + eventStartTime.Replace("\"", string.Empty) + "–" + eventEndTime.Replace("\"", string.Empty) + "<br />" + timeZone.Replace("\"", string.Empty) + "</span>" + "</p><p class=\"jtprow\"><span class=\"lbljtip\"> Address: </span>" + "<span class=\"dtlsjtip\">" + strAddress.Replace("\"", string.Empty) + "</span></p><p class=\"jtprow\"><span class=\"lbljtip\"> Owner: </span>" + "<span class=\"dtlsjtip\">" + salesRep.Replace("\"", string.Empty) + "<br />(" + franchisee.Replace("\"", string.Empty) + ")" + "</span></p>"; podName = "<p class=\"jtprow\"><span class=\"lbljtip\"> Pod Name: </span>"; podName = podName + "<span class=\"dtlsjtip\">"; if (eventForCalendar[count].EventPod != null) { for (int podcount = 0; podcount < eventForCalendar[count].EventPod.Count; podcount++) { podName = podName + eventForCalendar[count].EventPod[podcount].Pod.Name.Replace("\"", string.Empty) + "<br />"; } } podName = podName + "</span></p>"; eventStatus = "<p class=\"jtprow\"><span class=\"lbljtip\"> Event Status: </span>"; eventStatus += "<span class=\"dtlsjtip\">" + ((EventStatus)eventForCalendar[count].EventStatus).ToString() + "</span></p>"; jTipData = jTipData + podName + eventStatus + "<p class=\"jtprow\"><span class=\"lbljtip\"> Statistics/Health: </span> </p>" + "<p class=\"jtprowtop\"><span class=\"custcauntjtp\"><span class=\"ttxt\"> Registered Customers </span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].RegisteredCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Attended Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].AttendedCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Canceled Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].CancelCustomersCount.ToString().Replace("\"", string.Empty) + "</span></span></p>"; string strEventName = "<a class='jtip' title='" + jTipData + "'" + strEventView + " ><img src='../Images/addevent-square.gif' /><span class='celltxt_clnder'>" + salesRepInitials + " " + eventForCalendar[count].Host.Name + "<br>" + eventForCalendar[count].Host.Address.City + ", " + eventForCalendar[count].Host.Address.State + " - " + eventForCalendar[count].Host.Address.Zip + "</span></a>"; _tblAppointments.Rows.Add(new object[] { "Event" + eventForCalendar[count].EventID.ToString(), "Event", strEventName, eventForCalendar[count].EventDate, strEventDescription }); } } }
public void Update_ExistingEmployee_Territory() { string PhotoPath = Path.Combine(this.TestContext.DeploymentDirectory, "foto.jpg"); TerritoryRepository repoTerritory = new TerritoryRepository(); EmployeeRepository repoEmployee = new EmployeeRepository(); //se crean los empleados Employee employeeNew1 = new Employee() { FirstName = "name 1", LastName = "lastname 1", Localization = new Address() { Street = "Street 1", City = "City 1", Country = "Country 1" }, EmployeeExt = new EmployeeExtended() { Notes = "xx xx xx xx", Photo = ConvertImageToByteArray(new Bitmap(PhotoPath), ImageFormat.Jpeg), PhotoPath = PhotoPath } }; repoEmployee.Create(employeeNew1); Employee employeeNew2 = new Employee() { FirstName = "name 2", LastName = "lastname 2", Localization = new Address() { Street = "Street 2", City = "City 2", Country = "Country 2" }, EmployeeExt = new EmployeeExtended() { Notes = "xx xx xx", Photo = ConvertImageToByteArray(new Bitmap(PhotoPath), ImageFormat.Jpeg), PhotoPath = PhotoPath } }; repoEmployee.Create(employeeNew2); //se crea el territorio Territory territoryNew = new Territory() { TerritoryDescription = "territoty 1" }; repoTerritory.Create(territoryNew); //asignamos los empleados al territorio existente repoTerritory.AddEmployees(territoryNew, new List <Employee>(new Employee[] { employeeNew1, employeeNew2 })); //validamos que la asignacion se haya realizado correctamente //recuperando la entidad y sus relaciones var territorySel = repoTerritory.Single(x => x.TerritoryId == territoryNew.TerritoryId, new List <Expression <Func <Territory, object> > >() { x => x.Employees }); Assert.IsNotNull(territorySel); Assert.IsNotNull(territorySel.Employees); Assert.AreEqual(territorySel.Employees.Count, 2); }
public void Delete_AssignedEmployee_Territory() { TerritoryRepository repoTerritory = new TerritoryRepository(); EmployeeRepository repoEmployee = new EmployeeRepository(); //se crean los empleados Employee employeeNew1 = new Employee() { FirstName = "Name 1", LastName = "LastaName 1" }; repoEmployee.Create(employeeNew1); Employee employeeNew2 = new Employee() { FirstName = "Name 2", LastName = "LastaName 2" }; repoEmployee.Create(employeeNew2); //se crea el territorio Territory territoryNew = new Territory() { TerritoryDescription = "territoty 1" }; repoTerritory.Create(territoryNew); //asignamos los empleados al territorio existente repoTerritory.AddEmployees(territoryNew, new List <Employee>(new Employee[] { employeeNew1, employeeNew2 })); //validamos que la asignacion se haya realizado correctamente //recuperando la entidad y sus relaciones var territorySel = repoTerritory.Single(x => x.TerritoryId == territoryNew.TerritoryId, new List <Expression <Func <Territory, object> > >() { x => x.Employees }); Assert.IsNotNull(territorySel); Assert.IsNotNull(territorySel.Employees); Assert.AreEqual(territorySel.Employees.Count, 2); //removemos uno de los empleados asignados repoTerritory.RemoveEmployees(territoryNew, new List <Employee>(new Employee[] { employeeNew1 })); //recuperamos el territorio para validar que se haya eliminado el empleado var territorySel2 = repoTerritory.Single(x => x.TerritoryId == territoryNew.TerritoryId, new List <Expression <Func <Territory, object> > >() { x => x.Employees }); Assert.IsNotNull(territorySel2); Assert.IsNotNull(territorySel2.Employees); Assert.AreEqual(territorySel2.Employees.Count, 1); Employee employeeSel = territorySel2.Employees.First(); Assert.AreEqual(employeeSel.FirstName, employeeNew2.FirstName); Assert.AreEqual(employeeSel.LastName, employeeNew2.LastName); }
// // GET: /Territory/Details/5 public ActionResult Details(int id) { IRepository <Territory> repo = new TerritoryRepository(); return(View(repo.GetById(id))); }
// // GET: /Territory/ public ActionResult Index() { IRepository <Models.Territory> repo = new TerritoryRepository(); return(View(repo.GetAll())); }