public ActionResult Duplicate(string id) { DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient(); DirectEmployerClientCampus campus = campusclient.GetByRowKey(id); DirectEmployerClientCampusProgramClient campusprogramclient = new DirectEmployerClientCampusProgramClient(); List <DirectEmployerClientCampusProgram> campusprograms = new List <DirectEmployerClientCampusProgram>(campusprogramclient.GetAllByClientId(campus.ClientRowKey).Where(x => x.CampusRowKey == id)); //Create a copy of the campus DirectEmployerClientCampus campuscopy = new DirectEmployerClientCampus(); campuscopy.Address = campus.Address; campuscopy.CampusType = campus.CampusType; campuscopy.City = campus.Address; campuscopy.ClientId = campus.ClientId; campuscopy.ClientRowKey = campus.ClientRowKey; campuscopy.Name = "Copy of " + campus.Name; campuscopy.State = campus.State; campuscopy.Zip = campus.Zip; campusclient.AddNewItem(campuscopy); //Now create copies of Programs foreach (DirectEmployerClientCampusProgram program in campusprograms) { DirectEmployerClientCampusProgram pcopy = new DirectEmployerClientCampusProgram(); pcopy.ClientId = program.ClientId; pcopy.ClientRowKey = program.ClientRowKey; pcopy.CampusId = campuscopy.CampusId; pcopy.CampusRowKey = campuscopy.RowKey; pcopy.Name = program.Name; pcopy.ProgramId = program.ProgramId; pcopy.ProgramType = program.ProgramType; pcopy.Payout = program.Payout; pcopy.ProgramCategories = program.ProgramCategories; pcopy.TotalCap = program.TotalCap; pcopy.AnnualCap = program.AnnualCap; pcopy.MonthlyCap = program.MonthlyCap; pcopy.WeeklyCap = program.WeeklyCap; pcopy.DailyCap = program.DailyCap; pcopy.Status = program.Status; campusprogramclient.AddNewItem(pcopy); } return(RedirectToAction("Edit", "DirectEmployerClients", new { id = campus.ClientRowKey })); }
public ActionResult Create(DirectEmployerClientCampusProgram item) { try { if (ModelState.IsValid) { DirectEmployerClientCampusProgramClient programclient = new DirectEmployerClientCampusProgramClient(); item.PostedDateTime = DateTime.UtcNow; AttributeMaskCalculator amc = new AttributeMaskCalculator(); item.AttributeMask = amc.GetMask(item); ImportantThingsMaskCalculator itmc = new ImportantThingsMaskCalculator(); item.ImportantThingsMask = itmc.GetMask(item); try { programclient.AddNewItem(item); return(RedirectToAction("Edit", "DirectEmployerClientCampuses", new { id = item.CampusId })); } catch { ModelState.AddModelError("error", "Error creating new program"); } } DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient(); DirectEmployerClientCampus campus = campusclient.GetByRowKey(item.CampusId); ViewBag.Campus = campus; DirectEmployerClientClient dscc = new DirectEmployerClientClient(); ViewBag.Client = dscc.GetByRowKey(item.ClientRowKey); return(View(item)); } catch { DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient(); DirectEmployerClientCampus campus = campusclient.GetByRowKey(item.CampusId); ViewBag.Campus = campus; DirectEmployerClientClient dscc = new DirectEmployerClientClient(); ViewBag.Client = dscc.GetByRowKey(item.ClientRowKey); return(View()); } }