public void AgencyGroupsFilterTest() { User user = new User() { Id = 1, AgencyId = 1, RoleId = (int)FixedRoles.RegionOfficer }; IPermissionsBase target = PermissionsFactory.GetPermissionsFor(user); Func <AgencyGroup, bool> AgencyGroupsFilter = target.AgencyGroupsFilter.Compile(); AgencyGroup param = new AgencyGroup() { Country = new Country() { Region = new Region() { Users = new List <User>() { new User() { Id = 0 } } } } }; Assert.IsFalse(AgencyGroupsFilter(param)); param.Country.Region.Users.Add(user); Assert.IsTrue(AgencyGroupsFilter(param)); }
// // GET: /Admin/AgencyGroups/Edit/5 public ActionResult Edit(int id) { AgencyGroup agencygroup = db.AgencyGroups.Single(a => a.Id == id); PrepareViewBag(agencygroup.CountryId, agencygroup.StateId, agencygroup.Culture, agencygroup.DefaultCurrency); return(View(agencygroup)); }
public void AgencyGroupsFilterTest() { User user = new User() { Id = 1, AgencyId = 1, RoleId = (int)FixedRoles.AgencyUser }; IPermissionsBase target = PermissionsFactory.GetPermissionsFor(user); Func <AgencyGroup, bool> AgencyGroupsFilter = target.AgencyGroupsFilter.Compile(); AgencyGroup param = new AgencyGroup() { Agencies = new List <Agency>() { new Agency() { Users = new List <User>() { new User() { Id = 0 } } } } }; Assert.IsFalse(AgencyGroupsFilter(param)); param.Agencies.Add(new Agency() { Users = new List <User>() { user } }); Assert.IsTrue(AgencyGroupsFilter(param)); }
public ActionResult Delete(int id) { AgencyGroup agencygroup = db.AgencyGroups.Single(a => a.Id == id); ValidateDelete(id); return(View(agencygroup)); }
protected override void UpdateObject() { item = (AgencyGroup)ViewState["CurrentObject"]; item.AgencyGroupName = TenNhomDonVi.Text.Trim(); item.DisplayOrder = ThuTuHienThi.Text.ToInteger(); item.IsShowStatistic = HienThiThongKe.Checked; AgencyGroupServices.Update(item); }
protected override void CreateNewObject() { item = new AgencyGroup(); item.AgencyGroupName = TenNhomDonVi.Text.Trim(); item.DisplayOrder = ThuTuHienThi.Text.ToInteger(); item.IsShowStatistic = HienThiThongKe.Checked; AgencyGroupServices.Create(item); }
protected override void ShowObjectInformation() { item = AgencyGroupServices.GetById(IntId); ViewState["CurrentObject"] = item; TenNhomDonVi.Text = item.AgencyGroupName; ThuTuHienThi.Text = item.DisplayOrder.ToString(); HienThiThongKe.Checked = item.IsShowStatistic ?? false; }
protected void ProcessAgencies( IDictionary <string, Agency> dbAgencies, IDictionary <int, AgencyGroup> dbAgencyGroups, ProductEntity product, IEnumerable <Contract.Product.Agency> agencies) { foreach (var agency in agencies) { AgencyGroup dbAgencyGroup = null; if (!(string.IsNullOrEmpty(agency.AgencyGroupShortName) && string.IsNullOrEmpty(agency.AgencyGroupCode))) { var aGroupKey = HashCode.Combine(agency.AgencyGroupShortName?.ToUpperInvariant(), agency.AgencyGroupCode?.ToUpperInvariant()); if (!dbAgencyGroups.TryGetValue(aGroupKey, out dbAgencyGroup)) { dbAgencyGroup = _mapper.Map <AgencyGroup>(agency); dbAgencyGroups.Add(aGroupKey, dbAgencyGroup); _agencyGroups.Add(dbAgencyGroup); } } if (dbAgencies.TryGetValue(agency.AgencyIdentifier, out var dbAgency)) { if (!string.Equals(dbAgency.ShortName, agency.ShortName) || !string.Equals(dbAgency.Name, agency.Name)) { dbAgency.Name = agency.Name; dbAgency.ShortName = agency.ShortName; _agencies.Add(dbAgency); } } else { dbAgency = _mapper.Map <Agency>(agency); _agencies.Add(dbAgency); dbAgencies.Add(dbAgency.ExternalIdentifier, dbAgency); } // Product Agency activity period should fit the StartDate <= date < EndDate pattern in the database. // Due to the fact that Landmark sends StartDate/EndDate as inclusive dates without time part, // the Agency activity period is adjusted to fit the pattern above. _productAgencies.Add(new ProductAgency { Product = product, Agency = dbAgency, AgencyGroup = dbAgencyGroup, StartDate = agency.StartDate.Date, EndDate = agency.EndDate.Date.AddDays(1) }); } }
public ActionResult Edit(AgencyGroup agencygroup) { ValidateSave(agencygroup); if (ModelState.IsValid) { db.AgencyGroups.Attach(agencygroup); db.ObjectStateManager.ChangeObjectState(agencygroup, EntityState.Modified); db.SaveChanges(); return(RedirectToAction("Index")); } PrepareViewBag(agencygroup.CountryId, agencygroup.StateId, agencygroup.Culture, agencygroup.DefaultCurrency); return(View(agencygroup)); }
// // GET: /Admin/AgencyGroups/Delete/5 private void ValidateSave(AgencyGroup agencygroup) { if (agencygroup.CountryId != 0) { var country = db.Countries.Where(c => c.Id == agencygroup.CountryId).First(); if (country != null) { if (country.Name == "Israel" && agencygroup.ForceIsraelID == false) { ModelState.AddModelError(string.Empty, "For Country IL field 'Israel ID is required' should be checked."); } } } }
public static void CreateAgencyGroup(string GroupName, string CountryName, string StateName) { var context = new ccEntities(); AgencyGroup a = new AgencyGroup(); a.Name = GroupName; var ct = context.Countries.Where(x => x.Name == CountryName); var st = context.States.Where(x => x.Name == StateName); int c_id = 0, st_id = 0; if (ct.Any()) { c_id = ct.First().Id; } if (st.Any()) { st_id = st.First().Id; } var g = context.AgencyGroups.Where(c => c.Name == a.Name); if (!g.Any()) { AgencyGroup g_new = new AgencyGroup(); g_new.Name = GroupName; g_new.Addr1 = GroupName + "Test Addr1"; g_new.Addr2 = GroupName + " Test Addr2"; g_new.CountryId = c_id; if (st_id != 0) { g_new.StateId = st_id; } g_new.ReportingPeriodId = 1; context.AgencyGroups.AddObject(g_new); try { context.SaveChanges(); } catch (Exception ex) { } } }
public ActionResult Create(AgencyGroup agencygroup) { ValidateSave(agencygroup); if (db.AgencyGroups.Any(f => f.Id == agencygroup.Id)) { ModelState.AddModelError(string.Empty, "Org ID must be unique"); } if (ModelState.IsValid) { db.AgencyGroups.AddObject(agencygroup); db.SaveChanges(); if (!string.IsNullOrEmpty(GlobalDbSettings.GetString(GlobalDbSettings.GlobalStringNames.NewSerOrgNotifyEmail))) { EmailHelper.SendNewSerOrgNotification(true, agencygroup.Id, agencygroup.Name); } return(RedirectToAction("Index")); } PrepareViewBag(agencygroup.CountryId, agencygroup.StateId, agencygroup.Culture, agencygroup.DefaultCurrency); return(View(agencygroup)); }
public ActionResult DeleteConfirmed(int id) { ValidateDelete(id); AgencyGroup agencygroup = db.AgencyGroups.Single(a => a.Id == id); if (ModelState.IsValid) { db.AgencyGroups.DeleteObject(agencygroup); try { db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return(RedirectToAction("Index")); } else { return(View(agencygroup)); } }
// // GET: /Admin/AgencyGroups/Details/5 public ViewResult Details(int id) { AgencyGroup agencygroup = db.AgencyGroups.Single(a => a.Id == id); return(View(agencygroup)); }