private StaffAttributeVM ConvertStaffAttributeDC(StaffAttributeVMDC returnedObject) { StaffAttributeVM model = new StaffAttributeVM(); model.StaffAttributeItem = Mapper.Map <StaffAttributeDC, StaffAttributeModel>(returnedObject.StaffAttributeItem); RepopulateListsFromCacheSession(model); return(model); }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <param name="currentUserName"></param> /// <param name="appID"></param> /// <param name="overrideID"></param> /// <param name="code"></param> /// <param name="dataRepository"></param> /// <param name="uow"></param> /// <returns></returns> public StaffAttributeVMDC GetStaffAttribute(string userName, string currentUserName, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <StaffAttribute> dataRepository , IRepository <Staff> staffRepository , IRepository <Application> applicationRepository , IRepository <ApplicationAttribute> applicationAttributeRepository ) { try { using (uow) { // Convert code to Guid Guid codeGuid = Guid.Parse(code); // Retrieve specific StaffAttribute StaffAttribute dataEntity = dataRepository.Single(x => x.Code == codeGuid); // Convert to data contract for passing through service interface StaffAttributeDC destination = Mapper.Map <StaffAttribute, StaffAttributeDC>(dataEntity); IEnumerable <Staff> staffList = staffRepository.GetAll(); IEnumerable <Application> applicationList = applicationRepository.GetAll(); IEnumerable <ApplicationAttribute> applicationAttributeList = applicationAttributeRepository.GetAll(); List <StaffDC> staffDestinationList = Mapper.Map <List <StaffDC> >(staffList); List <ApplicationDC> applicationDestinationList = Mapper.Map <List <ApplicationDC> >(applicationList); List <ApplicationAttributeDC> applicationAttributeDestinationList = Mapper.Map <List <ApplicationAttributeDC> >(applicationAttributeList); // Create aggregate contract StaffAttributeVMDC message = new StaffAttributeVMDC(); message.StaffAttributeItem = destination; message.StaffList = staffDestinationList; message.ApplicationList = applicationDestinationList; message.ApplicationAttributeList = applicationAttributeDestinationList; return(message); } } catch (Exception e) { //Prevent exception from propogating across the service interface ExceptionManager.ShieldException(e); return(null); } }
//This method is shared between create and save private ActionResult UpdateStaffAttribute() { var model = GetUpdatedModel(); var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors[0].ErrorMessage }) .ToArray(); //Set flags false SetFlagsFalse(model); if (ModelState.IsValid) { //Attempt update try { AdminServiceClient sc = new AdminServiceClient(); StaffAttributeDC StaffAttributeToCreate = Mapper.Map <StaffAttributeDC>(model.StaffAttributeItem); StaffAttributeVMDC returnedObject = null;//sc.SaveStaffAttribute(SessionManager.UserID, SessionManager.UserID, "SecurityMonitoring", "", StaffAttributeToCreate); var createdStaffAttribute = returnedObject.StaffAttributeItem; model.StaffAttributeItem = Mapper.Map <StaffAttributeModel>(createdStaffAttribute); //After creation some of the fields are display only so we need the resolved look up nmames ResolveFieldCodesToFieldNamesUsingLists(model); //model.AccessContext = StaffAttributeAccessContext.Edit; //SessionManager.StaffAttributeDBVersion = model.StaffAttributeItem; //SessionManager.CurrentStaffAttribute = model.StaffAttributeItem; // Remove the state from the model as these are being populated by the controller and the HTML helpers are being populated with // the POSTED values and not the changed ones. ModelState.Clear(); model.Message = Resources.MESSAGE_UPDATE_SUCCEEDED; } catch (Exception e) { model.Message = Resources.MESSAGE_UPDATE_FAILED; return(View(model)); } } return(View(model)); }
// GET: /StaffAttribute/Edit?code= public ActionResult Edit(string code) { StaffAttributeVM model = new StaffAttributeVM(); //Not from staff or error if (String.IsNullOrEmpty(code)) { //If session has lists then use them RepopulateListsFromCacheSession(model); //Assume we are in create mode as no code passed model.StaffAttributeItem = new StaffAttributeModel(); } //if we have been passed a code then assume we are in edit situation and we need to retreive from the database. else { try { AdminServiceClient sc = new AdminServiceClient(); StaffAttributeVMDC returnedObject = null;//sc.GetSecurityCheckAndLookUps(SessionManager.UserID, SessionManager.UserID, "SecurityMonitoring", "", false, code); //Get view model from database model = ConvertStaffAttributeDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the DB version of the check. //SessionManager.StaffAttributeDBVersion = model.StaffAttributeItem; } catch (Exception e) { SetAccessContext(model); model.Message = Resources.MESSAGE_RETREIVAL_FAILED; return(View(model)); } } //Adds current retreived StaffAttribute to session //SessionManager.CurrentStaffAttribute = model.StaffAttributeItem; //SetAccessContext(model); return(View(model)); }
private void AddListsToSession(StaffAttributeVMDC returnedObject) { //********************************* //*PLACE HOLDER FOR SESSION LISTS * //********************************* }