// GET: /Edit public ActionResult Edit(int id) { //Get Item From Database LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); //Check Exists if (group == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Check Access RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } TablesDomainHierarchyLevelRepository tablesDomainHierarchyLevelRepository = new TablesDomainHierarchyLevelRepository(); SelectList hierarchyTypesList = new SelectList(tablesDomainHierarchyLevelRepository.GetDomainHierarchies(groupName).ToList(), "HierarchyLevelTableName", "HierarchyLevelTableName"); ViewData["HierarchyTypes"] = hierarchyTypesList; localOperatingHoursGroupRepository.EditGroupForDisplay(group); return(View(group)); }
//Add Data From Linked Tables for Display public void EditGroupForDisplay(LocalOperatingHoursGroup group) { group.LocalOperatingHoursGroupName = Regex.Replace(group.LocalOperatingHoursGroupName, @"[^\w\-()*]", "-"); fnDesktopDataAdmin_SelectLocalOperatingHoursGroupHierarchy_v1Result hierarchy = GetGroupHierarchy(group.LocalOperatingHoursGroupId); if (hierarchy != null) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); HierarchyGroup hierarchyGroup = hierarchyRepository.GetHierarchyGroup( hierarchy.HierarchyType ?? "", hierarchy.HierarchyCode ?? "", hierarchy.HierarchyName ?? "", hierarchy.TravelerTypeGuid ?? "", hierarchy.TravelerTypeName ?? "", hierarchy.SourceSystemCode ?? "" ); if (hierarchyGroup != null) { group.HierarchyType = hierarchyGroup.HierarchyType; group.HierarchyCode = hierarchyGroup.HierarchyCode; group.HierarchyItem = hierarchyGroup.HierarchyItem; group.ClientSubUnitGuid = hierarchyGroup.ClientSubUnitGuid; group.ClientSubUnitName = hierarchyGroup.ClientSubUnitName; group.TravelerTypeGuid = hierarchyGroup.TravelerTypeGuid; group.TravelerTypeName = hierarchyGroup.TravelerTypeName; group.ClientTopUnitName = hierarchyGroup.ClientTopUnitName; group.SourceSystemCode = hierarchyGroup.SourceSystemCode; } } }
//Delete Group public void Delete(LocalOperatingHoursGroup group) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_DeleteLocalOperatingHoursGroup_v1( group.LocalOperatingHoursGroupId, adminUserGuid, group.VersionNumber); }
// GET: /lIST/ public ActionResult List(int id, int?page, string sortField, int?sortOrder) { //Check Parent Exists LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); if (group == null) { ViewData["ActionMethod"] = "ListGet"; return(View("RecordDoesNotExistError")); } //Set Access Rights ViewData["Access"] = ""; RolesRepository rolesRepository = new RolesRepository(); if (rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id)) { ViewData["Access"] = "WriteAccess"; } //Sorting if (sortField != "OpeningDateTime" && sortField != "ClosingDateTime") { sortField = "WeekdayName"; } ViewData["CurrentSortField"] = sortField; //SortOrder if (sortOrder == 1) { ViewData["NewSortOrder"] = 0; ViewData["CurrentSortOrder"] = 1; } else { ViewData["NewSortOrder"] = 1; ViewData["CurrentSortOrder"] = 0; } ViewData["DeletedFlag"] = false; LocalOperatingHoursGroup localOperatingHoursGroup = new LocalOperatingHoursGroup(); localOperatingHoursGroup = localOperatingHoursGroupRepository.GetGroup(id); ViewData["LocalOperatingHoursGroupId"] = localOperatingHoursGroup.LocalOperatingHoursGroupId; ViewData["LocalOperatingHoursGroupName"] = localOperatingHoursGroup.LocalOperatingHoursGroupName; //return items var cwtPaginatedList = localOperatingHoursRepository.PageLocalOperatingHoursItems(id, page ?? 1, "", sortField, sortOrder ?? 0); return(View(cwtPaginatedList)); }
public ActionResult Delete(int id, int weekDayId, DateTime openingDateTime, FormCollection collection) { //Get Item LocalOperatingHoursItem localOperatingHoursItem = new LocalOperatingHoursItem(); localOperatingHoursItem = localOperatingHoursRepository.GetItem(id, weekDayId, openingDateTime); //Check Exists if (localOperatingHoursItem == null) { ViewData["ActionMethod"] = "GetDelete"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(localOperatingHoursItem.LocalOperatingHoursGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Parent LocalOperatingHoursGroup localOperatingHoursGroup = new LocalOperatingHoursGroup(); localOperatingHoursGroup = localOperatingHoursGroupRepository.GetGroup(localOperatingHoursItem.LocalOperatingHoursGroupId); try { localOperatingHoursItem.VersionNumber = Int32.Parse(collection["VersionNumber"]); localOperatingHoursRepository.Delete(localOperatingHoursItem); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/PolicyAirVendorGroupItem.mvc/Delete?id=" + localOperatingHoursItem.LocalOperatingHoursGroupId + "&weekDayId=" + localOperatingHoursItem.WeekDayId + "&openingDateTime=" + localOperatingHoursItem.OpeningDateTime; return(View("VersionError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } //Return return(RedirectToAction("List", new { id = localOperatingHoursGroup.LocalOperatingHoursGroupId })); }
//Add Group public void Add(LocalOperatingHoursGroup group) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_InsertLocalOperatingHoursGroup_v1( adminUserGuid, group.LocalOperatingHoursGroupName, group.HierarchyType, group.HierarchyCode, group.TravelerTypeGuid, group.ClientSubUnitGuid, group.SourceSystemCode, adminUserGuid ); }
// GET: /View public ActionResult View(int id) { LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); //Check Exists if (group == null) { ViewData["ActionMethod"] = "ViewGet"; return(View("RecordDoesNotExistError")); } localOperatingHoursGroupRepository.EditGroupForDisplay(group); return(View(group)); }
public ActionResult Delete(int id, FormCollection collection) { //Get Item From Database LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); //Check Exists if (group == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } //Check Access RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Delete Item try { group.VersionNumber = Int32.Parse(collection["VersionNumber"]); localOperatingHoursGroupRepository.Delete(group); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/LocalOperatingHoursGroup.mvc/UnDelete/" + group.LocalOperatingHoursGroupId; return(View("VersionError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List")); }
// GET: /Create public ActionResult Create(int id) { LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); //Check Exists if (group == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } WeekdayRepository weekdayRepository = new WeekdayRepository(); SelectList weekdayList = new SelectList(weekdayRepository.GetAllWeekdays().ToList(), "WeekdayId", "WeekdayName"); ViewData["Weekdays"] = weekdayList; ViewData["hourList"] = new SelectList(new[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11" } .Select(x => new { value = x, text = x }), "value", "text", ""); LocalOperatingHoursItem localOperatingHoursItem = new LocalOperatingHoursItem(); localOperatingHoursItem.LocalOperatingHoursGroupName = group.LocalOperatingHoursGroupName; localOperatingHoursItem.LocalOperatingHoursGroupId = group.LocalOperatingHoursGroupId; return(View(localOperatingHoursItem)); }
// GET: /Create public ActionResult Create() { //Check Access Rights to Domain if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } TripTypeRepository tripTypeRepository = new TripTypeRepository(); SelectList tripTypesList = new SelectList(tripTypeRepository.GetAllTripTypes().ToList(), "TripTypeId", "TripTypeDescription"); ViewData["TripTypes"] = tripTypesList; TablesDomainHierarchyLevelRepository tablesDomainHierarchyLevelRepository = new TablesDomainHierarchyLevelRepository(); SelectList hierarchyTypesList = new SelectList(tablesDomainHierarchyLevelRepository.GetDomainHierarchies(groupName).ToList(), "HierarchyLevelTableName", "HierarchyLevelTableName"); ViewData["HierarchyTypes"] = hierarchyTypesList; LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); return(View(group)); }
public ActionResult Delete(int id) { //Get Item From Database LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); //Check Exists if (group == null) { ViewData["ActionMethod"] = "DeleteGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } localOperatingHoursGroupRepository.EditGroupForDisplay(group); return(View(group)); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(LocalOperatingHoursItem localOperatingHoursItem) { WeekdayRepository weekdayRepository = new WeekdayRepository(); Weekday weekday = new Weekday(); weekday = weekdayRepository.GetWeekday(localOperatingHoursItem.WeekDayId); if (weekday != null) { localOperatingHoursItem.WeekdayName = weekday.WeekdayName; } LocalOperatingHoursGroupRepository localOperatingHoursGroupRepository = new LocalOperatingHoursGroupRepository(); LocalOperatingHoursGroup localOperatingHoursGroup = new LocalOperatingHoursGroup(); localOperatingHoursGroup = localOperatingHoursGroupRepository.GetGroup(localOperatingHoursItem.LocalOperatingHoursGroupId); if (localOperatingHoursGroup != null) { localOperatingHoursItem.LocalOperatingHoursGroupName = localOperatingHoursGroup.LocalOperatingHoursGroupName; } string openingTime; if (localOperatingHoursItem.OpeningDateTime.Hour < 10) { openingTime = String.Concat("0", localOperatingHoursItem.OpeningDateTime.Hour, ":"); } else { openingTime = String.Concat(localOperatingHoursItem.OpeningDateTime.Hour, ":"); } if (localOperatingHoursItem.OpeningDateTime.Minute < 10) { openingTime = String.Concat(openingTime, "0", localOperatingHoursItem.OpeningDateTime.Minute); } else { openingTime = String.Concat(openingTime, localOperatingHoursItem.OpeningDateTime.Minute); } if (localOperatingHoursItem.OpeningDateTime.Second != 0) { if (localOperatingHoursItem.OpeningDateTime.Second < 10) { openingTime = String.Concat(openingTime, ":0", localOperatingHoursItem.OpeningDateTime.Second); } else { openingTime = String.Concat(openingTime, ":", localOperatingHoursItem.OpeningDateTime.Second); } } localOperatingHoursItem.OpeningTime = openingTime; string serviceFundEndTime; if (localOperatingHoursItem.ClosingDateTime.Hour < 10) { serviceFundEndTime = String.Concat("0", localOperatingHoursItem.ClosingDateTime.Hour, ":"); } else { serviceFundEndTime = String.Concat(localOperatingHoursItem.ClosingDateTime.Hour, ":"); } if (localOperatingHoursItem.ClosingDateTime.Minute < 10) { serviceFundEndTime = String.Concat(serviceFundEndTime, "0", localOperatingHoursItem.ClosingDateTime.Minute); } else { serviceFundEndTime = String.Concat(serviceFundEndTime, localOperatingHoursItem.ClosingDateTime.Minute); } if (localOperatingHoursItem.ClosingDateTime.Second != 0) { if (localOperatingHoursItem.ClosingDateTime.Second < 10) { serviceFundEndTime = String.Concat(serviceFundEndTime, ":0", localOperatingHoursItem.ClosingDateTime.Second); } else { serviceFundEndTime = String.Concat(serviceFundEndTime, ":", localOperatingHoursItem.ClosingDateTime.Second); } } localOperatingHoursItem.ClosingTime = serviceFundEndTime; }
public ActionResult Create(LocalOperatingHoursItem localOperatingHoursItem) { LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(localOperatingHoursItem.LocalOperatingHoursGroupId); //Check Exists if (group == null) { ViewData["ActionMethod"] = "CreateGet"; return(View("RecordDoesNotExistError")); } //Check AccessRights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(localOperatingHoursItem.LocalOperatingHoursGroupId)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Update Model from Form try { UpdateModel(localOperatingHoursItem); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Convert Times to DateTime for DB localOperatingHoursItem.OpeningDateTime = CWTStringHelpers.BuildDateTime(localOperatingHoursItem.OpeningTime); localOperatingHoursItem.ClosingDateTime = CWTStringHelpers.BuildDateTime(localOperatingHoursItem.ClosingTime); //Already Exists? LocalOperatingHoursItem localOperatingHoursItemOriginal = localOperatingHoursRepository.GetItem( localOperatingHoursItem.LocalOperatingHoursGroupId, localOperatingHoursItem.WeekDayId, localOperatingHoursItem.OpeningDateTime ); if (localOperatingHoursItemOriginal != null) { try { localOperatingHoursRepository.Delete(localOperatingHoursItemOriginal); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/LocalOperatingHoursItem.mvc/Create/" + localOperatingHoursItem.LocalOperatingHoursGroupId; return(View("VersionError")); } //Generic Error ViewData["Message"] = "Unknown DBError"; return(View("Error")); } } try { localOperatingHoursRepository.Add(localOperatingHoursItem); } catch (SqlException ex) { LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } //Return To List return(RedirectToAction("List", new { id = localOperatingHoursItem.LocalOperatingHoursGroupId })); }
public ActionResult Edit(int id, FormCollection collection) { //Get Item From Database LocalOperatingHoursGroup group = new LocalOperatingHoursGroup(); group = localOperatingHoursGroupRepository.GetGroup(id); //Check Exists if (group == null) { ViewData["ActionMethod"] = "EditPost"; return(View("RecordDoesNotExistError")); } //Check Access Rights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToLocalOperatingHoursGroup(id)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Update Model From Form + Validate against DB try { UpdateModel(group); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //ClientSubUnitTravelerType has extra field string hierarchyCode = group.HierarchyCode; if (group.HierarchyType == "ClientSubUnitTravelerType") { group.ClientSubUnitGuid = hierarchyCode; //ClientSubUnitTravelerType has 2 primarykeys } //Check Access Rights to PolicyGroup HierarchyRepository hierarchyRepository = new HierarchyRepository(); if (!hierarchyRepository.AdminHasDomainHierarchyWriteAccess(group.HierarchyType, hierarchyCode, group.SourceSystemCode, groupName)) { ViewData["Message"] = "You cannot add to this hierarchy item"; return(View("Error")); } //Database Update try { localOperatingHoursGroupRepository.Edit(group); } catch (SqlException ex) { //Versioning Error if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/LocalOperatingHoursGroup.mvc/Edit/" + group.LocalOperatingHoursGroupId; return(View("VersionError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List")); }
public ActionResult Create(LocalOperatingHoursGroup group) { //Check Access Rights to Domain if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } //Check Access Rights to Domain Hierarchy if (!hierarchyRepository.AdminHasDomainHierarchyWriteAccess(group.HierarchyType, group.HierarchyCode, group.SourceSystemCode, groupName)) { ViewData["Message"] = "You cannot add to this hierarchy item"; return(View("Error")); } //Update Model From Form + Validate against DB try { UpdateModel(group); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //ClientSubUnitTravelerType has extra field string hierarchyCode = group.HierarchyCode; if (group.HierarchyType == "ClientSubUnitTravelerType") { group.ClientSubUnitGuid = hierarchyCode; //ClientSubUnitTravelerType has 2 primarykeys } //Database Update try { localOperatingHoursGroupRepository.Add(group); } catch (SqlException ex) { //Non-Unique Name if (ex.Message == "NonUniqueName") { return(View("NonUniqueNameError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } ViewData["NewSortOrder"] = 0; return(RedirectToAction("List")); }