public ActionResult Add(StaffVM model) { try { var modelAdd = model.search.GetEntity(); var msgValid = ValidateModel(modelAdd); if (string.IsNullOrEmpty(msgValid)) { var obj = _userRepository.Add(modelAdd); if (obj) { return(Json(new { status = true })); } else { return(Json(new { status = false, msg = "Thêm thất bại" })); } } else { return(Json(new { status = false, msg = msgValid })); } } catch (Exception ex) { // chuyển sang page ERR return(RedirectToAction("Index", "Error")); } }
public async Task <IActionResult> AddStaff(StaffVM vm) { var addedStaffInt = await _adminRepo.AddStaff(vm); var staffTypeId = vm.StaffTypeID; var staffTypeName = (await _adminRepo.GetStaffTypeById(vm.StaffTypeID)).Type; dynamic obj = null; string nextViewName = "Add" + staffTypeName; switch (staffTypeName) { case nameof(Pilot): obj = new Pilot { StaffID = addedStaffInt }; break; case nameof(Steward): obj = new Steward { StaffID = addedStaffInt }; break; default: break; } return(View(nextViewName, obj)); }
public async Task <IActionResult> Create([Bind("Id,Surname,FirstName,Email,FirstAider,IsActive")] StaffVM staffVM) { if (ModelState.IsValid) { try { Staff staff = new Staff(); staff.Surname = staffVM.Surname; staff.FirstName = staffVM.FirstName; staff.Email = staffVM.Email; staff.FirstAider = staffVM.FirstAider; staff.IsActive = true; _context.Add(staff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch { staffVM.Message = "Something went wrong. Please ensure all fields are completed and try again"; return(View(staffVM)); } } return(View(staffVM)); }
private void AddStaff() { try { var NewStaff = new StaffVM { Designation = Enums.Roles.CompanyAdmin.ToString(), EmailAddress = txtEmailAddress.Text, FirstName = txtFirstName.Text, LastName = txtLastName.Text, PhoneNumber = txtPhoneNumber.Text, StaffNumber = txtStaffNumber.Text, StaffId = new Random().Next(1000, 100000), CompanyId = ddlCompany.SelectedValue }; var response = _httpHelper.Post(NewStaff, appConfig.apiBaseUrl + "/api/Staff"); if (response.IsSuccessStatusCode) { // var strresponse = _httpHelper.ReadString(response); Server.Transfer("/Pages/Staff/View.aspx"); } } catch (Exception ex) { LogHelper.Log(ex); } }
public async Task <WrapperStaffListVM> Delete(StaffVM Temp) { var Task = await _repositoryWrapper.Staff.FindByConditionAsync(x => x.Id == Temp.Id && x.FactoryId == Temp.FactoryId); var datarow = Task.ToList().FirstOrDefault(); if (datarow == null) { return(new WrapperStaffListVM()); } _repositoryWrapper.Staff.Delete(datarow); await _repositoryWrapper.Staff.SaveChangesAsync(); this._utilService.Log("Successful In Deleting Data"); var dataParam = new GetDataListVM() { FactoryId = Temp.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperStaffListVM data = await GetListPaged(dataParam, true); return(data); }
/// <summary> /// Private method to merge in the model /// </summary> /// <returns></returns> private StaffVM GetUpdatedModel() { StaffVM model = new StaffVM(); RepopulateListsFromCacheSession(model); model.Message = ""; if (SessionManager.CurrentStaff != null) { model.StaffItem = SessionManager.CurrentStaff; } //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING ************************** bool result = TryUpdateModel(model);//This also validates and sets ModelState //******************************************************************************************************************************* if (SessionManager.CurrentStaff != null) { //*****************************************PREVENT OVER POSTING ATTACKS****************************************************** //Get the values for read only fields from session MergeNewValuesWithOriginal(model.StaffItem); //*************************************************************************************************************************** } SetAccessContext(model); return(model); }
public async Task <ActionResult <WrapperStaffListVM> > DeleteStaff([FromBody] StaffVM Temp) { WrapperStaffListVM data = await _serviceWrapper.StaffService.Delete(Temp); _utilService.Log("Staff Successfully Deleted"); return(data); }
private void AddStaff() { try { var NewStaff = new StaffVM { Designation = ddlDesignation.SelectedItem.Text, EmailAddress = txtEmailAddress.Text, FirstName = txtFirstName.Text, LastName = txtLastName.Text, PhoneNumber = txtPhoneNumber.Text, StaffNumber = txtStaffNumber.Text, StaffId = new Random().Next(1000, 100000), CompanyId = CurrentUser.CompanyId }; var response = _httpHelper.Post(NewStaff, appConfig.apiBaseUrl + "/api/Staff"); if (response.IsSuccessStatusCode) { Server.Transfer("/Pages/Staff/View.aspx"); } } catch (Exception ex) { LogHelper.Log(ex); } }
public int Add(StaffVM oStaffModel) { var oStaffProfile = _mappingHelper.Map <Staff>(oStaffModel); _staffRepo.Add(oStaffProfile, GetType().Name); return(1); }
private async Task <WrapperStaffListVM> SetHistoryOverview(WrapperStaffListVM vm, string factoryId) { var data = new GetDataListHistory(); //Task<WrapperStaffHistory>[] listOftask = new Task<WrapperStaffHistory>[vm.ListOfData.Count]; WrapperStaffHistory[] listOftask = new WrapperStaffHistory[vm.ListOfData.Count]; for (int i = 0; i < vm.ListOfData.Count; i++) { StaffVM temp = vm.ListOfData.ElementAt(i); data.ClientId = temp.Id; data.PageNumber = -1; data.FactoryId = factoryId; data.PageSize = -1; listOftask[i] = await GetStaffHistory(data); // StaffHistory te = GetStaffHistoryOverview(listOftask[i]); int len = listOftask[i].ListOfData.Count - 1; vm.ListOfData.ElementAt(i).PaidAmount = listOftask[i].ListOfData[len].PaidAmount; vm.ListOfData.ElementAt(i).RecievableAmount = listOftask[i].ListOfData[len].RecievableAmount; vm.ListOfData.ElementAt(i).RecievedAmount = listOftask[i].ListOfData[len].RecievedAmount; vm.ListOfData.ElementAt(i).PayableAmount = listOftask[i].ListOfData[len].PayableAmount; } // await Task.WhenAll(listOftask); //for (int i = 0; i < vm.ListOfData.Count; i++) //{ //} return(vm); }
public StaffingVM(Data.Staffing staffing, StaffVM staff, EventVM @event) { StaffId = staffing.StaffId; Staff = staff; EventId = staffing.EventId; Event = @event; }
public async Task <WrapperStaffListVM> Update(string id, StaffVM ViewModel) { if (id != ViewModel.Id) { new WrapperStaffListVM(); } Task <IEnumerable <Staff> > itemsDB = _repositoryWrapper.Staff.FindByConditionAsync(x => x.Id == id && x.FactoryId == ViewModel.FactoryId); await Task.WhenAll(itemsDB); var itemUpdated = _utilService.GetMapper().Map <StaffVM, Staff>(ViewModel, itemsDB.Result.ToList().FirstOrDefault()); _repositoryWrapper.Staff.Update(itemUpdated); Task <int> t1 = _repositoryWrapper.Staff.SaveChangesAsync(); await Task.WhenAll(t1); this._utilService.Log("Successful In Updating Data"); var dataParam = new GetDataListVM() { FactoryId = ViewModel.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperStaffListVM data = await GetListPaged(dataParam, true); return(data); }
public ActionResult Create(StaffVM sta) { try { if (!ModelState.IsValid) { return(View(sta)); } var staff = _mapper.Map <Staff>(sta); staff.Registered = DateTime.Now; var isSuccess = _repo.Create(staff); if (!isSuccess) { ModelState.AddModelError("", "Check for Information"); return(View(sta)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Check for Information"); return(View()); } }
public int Add(StaffVM oStaffModel) { var oStaffProfile = _mappingHelper.Map <Staff>(oStaffModel); _staffRepo.Add(oStaffProfile, GetType().Name); return(this.unitOfWork.SaveChanges()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CurrentUser = (StaffVM)Session["CurrentUser"]; loadClients(CurrentUser.CompanyId); } }
private void RepopulateListsFromCacheSession(StaffVM model) { // Populate cached lists if they are empty. Will invoke service call StaffLookupListsCacheObject CachedLists = CacheManager.StaffListCache; // Retrieve any cached lists to model model.GradeList = CachedLists.GradeList; }
public async Task <WrapperStaffListVM> GetListPaged(GetDataListVM dataListVM, bool withHistory) { IEnumerable <Staff> ListTask = await _repositoryWrapper.Staff.FindByConditionAsync(x => x.FactoryId == dataListVM.FactoryId); long noOfRecordTask = await _repositoryWrapper.Staff.NumOfRecord(); List <Staff> List = ListTask.ToList().OrderByDescending(x => x.UpdatedDateTime).ToList();//.Skip((dataListVM.PageNumber - 1) * dataListVM.PageSize).Take(dataListVM.PageSize).OrderByDescending(x => x.CreatedDateTime).ToList(); List <StaffVM> outputList = new List <StaffVM>(); outputList = _utilService.GetMapper().Map <List <Staff>, List <StaffVM> >(List); List <UserRole> userRoleListT = await _repositoryWrapper .UserRole .FindAll() .Where(x => x.FactoryId == dataListVM.FactoryId) .Include(x => x.Role) .Include(x => x.UserAuthInfo) .ToListAsync(); for (int i = 0; i < userRoleListT.Count(); i++) { StaffVM staff = outputList.Where(x => x.Id == userRoleListT.ElementAt(i).UserAuthInfo.UserId).FirstOrDefault(); if (staff != null) { staff.Role = userRoleListT.ElementAt(i).Role.Name; staff.UserName = userRoleListT.ElementAt(i).UserAuthInfo.UserName; } } if (!string.IsNullOrEmpty(dataListVM.GlobalFilter) && !string.IsNullOrWhiteSpace(dataListVM.GlobalFilter)) { outputList = outputList.Where(output => output.AlternateCellNo != null ? output.AlternateCellNo.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.CellNo != null ? output.CellNo.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.Email != null ? output.Email.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.Name != null ? output.Name.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.PermanentAddress != null ? output.PermanentAddress.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.PresentAddress != null ? output.PresentAddress.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false).ToList(); } outputList = outputList.Skip((dataListVM.PageNumber - 1) * dataListVM.PageSize).Take(dataListVM.PageSize).ToList(); var data = new WrapperStaffListVM(); data.ListOfData = outputList; data.TotalRecords = noOfRecordTask; this._utilService.Log("Successful In Getting Data"); if (withHistory) { data = await SetHistoryOverview(data, dataListVM.FactoryId); } return(data); }
public async Task <ActionResult <WrapperStaffListVM> > AddToStaff([FromBody] StaffVM VM) { WrapperStaffListVM result = new WrapperStaffListVM(); result = await _serviceWrapper.StaffService.AddToIT_Admin(VM); _utilService.Log("Staff Successfully Added"); return(Ok(result)); }
public ActionResult Edit() { // Retrieve ID from session string code = sessionManager.StaffCode; StaffVM model = new StaffVM(); // 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.StaffItem = new StaffModel() { IsActive = true }; } //if we have been passed a code then assume we are in edit situation and we need to retrieve from the database. else { // Create service instance IUcbService sc = UcbService; try { // Call service to get Staff item and any associated lookups StaffVMDC returnedObject = sc.GetStaff(CurrentUser, CurrentUser, appID, "", code); // Close service communication ((ICommunicationObject)sc).Close(); //Get view model from service model = ConvertStaffDC(returnedObject); ResolveFieldCodesToFieldNamesUsingLists(model); //Store the service version sessionManager.StaffServiceVersion = model.StaffItem; } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } } //Adds current retrieved Staff to session sessionManager.CurrentStaff = model.StaffItem; SetAccessContext(model); return(View(model)); }
private void SetFlagsFalse(StaffVM model) { model.IsExitConfirmed = "False"; model.IsNewConfirmed = "False"; //Stop the binder resetting the posted values ModelState.Remove("IsDeleteConfirmed"); ModelState.Remove("IsExitConfirmed"); ModelState.Remove("IsNewConfirmed"); }
//Returns view of staff record which can be edited, based on staff id provided public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } StaffVM staff = new StaffVM(await _context.Staff.FirstOrDefaultAsync(m => m.Id == id)); return(View(staff)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CurrentUser = (StaffVM)Session["CurrentUser"]; //if (CurrentUser == null) // Server.Transfer(Server.MapPath("~/default.aspx")); loadClients("1"); } }
public async Task <ActionResult> StaffDashboard() { StaffVM model = new StaffVM(); var term = await Db.Terms.Where(x => x.ActiveTerm.Equals(true)).Select(x => x.TermName).FirstOrDefaultAsync(); var session = await Db.Sessions.Where(x => x.ActiveSession.Equals(true)).Select(x => x.SessionName).FirstOrDefaultAsync(); //get the ID of the logged in Staff var staffName = User.Identity.GetUserName(); var teacherAssignedClass = await Db.AssignFormTeacherToClasses.AsNoTracking().Where(x => x.Username.Equals(staffName)).Select(x => x.ClassName).FirstOrDefaultAsync(); // var formTeacherAssignedClass = Db.AssignFormTeacherToClasses.Where(x => x.Username.Equals(staffName)); var classAssignedToStudent = Db.AssignedClasses.Where(x => x.ClassName.Equals(teacherAssignedClass)).Select(x => x.StudentId.Count()); //number of male student in the class of the form Teacher var male = Db.AssignedClasses.AsNoTracking().Where( x => x.TermName.Equals(term) && x.SessionName.Equals(session) && x.ClassName.Equals(teacherAssignedClass)).Count(x => x.Student.Gender.Equals("MALE")); //number of female student in the class of the form Teacher var female = Db.AssignedClasses.AsNoTracking().Where( x => x.TermName.Equals(term) && x.SessionName.Equals(session) && x.ClassName.Equals(teacherAssignedClass)).Count(x => x.Student.Gender.Equals("FEMALE")); // var classIWasAssignedTo = Db. //get all the student in the class of a staff var studentInMyClass = Db.AssignedClasses.AsNoTracking() .Where(x => x.ClassName.Equals(teacherAssignedClass)) .Select(x => x.StudentId).ToList(); var mylist = new List <Student>(); foreach (var item in studentInMyClass) { var student = await Db.Students.Where(x => x.StudentId.Equals(item)).FirstOrDefaultAsync(); mylist.Add(student); } model.StudentsInMyClass = mylist; model.ClassName = teacherAssignedClass; model.MaleStudent = male; model.FemaleStudent = female; model.TotalStudentInClass = studentInMyClass.Count(); return(View(model)); }
public ActionResult GetLstUser(StaffVM modelSearch, int?page) { int totalRecord = 0; var model = _userRepository.GetLst(modelSearch.search.GetEntity(), page, NumberRecord, out totalRecord); return(Json(new { view = RenderRazorViewToString(ControllerContext, "LstView", model) })); //return PartialView(model); }
protected void Page_Load(object sender, EventArgs e) { currentUser = (StaffVM)Session["CurrentUser"]; var _httpHelper = new HttpHelper(); var url = $"{appConfig.apiBaseUrl}/api/case?companyid={currentUser.CompanyId}"; var strResponse = _httpHelper.GetString(url); var oCaseList = SerializationServices.DeserializeJson <List <CaseVM> >(strResponse); gdvCasesList.DataSource = oCaseList; gdvCasesList.DataBind(); }
private void DetermineIsDirty(StaffVM model) { //Compare the Staff to the original session if (model.StaffItem.PublicInstancePropertiesEqual(SessionManager.StaffServiceVersion, "RowIdentifier")) { model.IsViewDirty = false; } else { model.IsViewDirty = true; } }
private StaffVM ConvertStaffDC(StaffVMDC returnedObject) { StaffVM model = new StaffVM(); // Map Staff Item model.StaffItem = Mapper.Map <StaffDC, StaffModel>(returnedObject.StaffItem); // Map lookup data lists model.GradeList = Mapper.Map <IEnumerable <GradeDC>, List <GradeModel> >(returnedObject.GradeList); return(model); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CurrentUser = (StaffVM)Session["CurrentUser"]; if (CurrentUser == null) { Server.Transfer("./default.aspx"); } loadClients(CurrentUser.CompanyId); } }
// GET: SearchStaff public ActionResult Index() { int totalRecord = 0; var model = new StaffVM { search = new StaffModel(), LstStaff = _userRepository.GetLst(new staff(), 1, NumberRecord, out totalRecord), PageNumber = 1, PageCount = NumberRecord }; model.ToTalPage = (totalRecord % NumberRecord == 0) ? totalRecord / NumberRecord : totalRecord / NumberRecord + 1; return(View(model)); }
private void SetAccessContext(StaffVM model) { //Decide on access context if (null == model.StaffItem || model.StaffItem.Code == Guid.Empty) { // Create context model.AccessContext = StaffAccessContext.Create; } else { // Edit context model.AccessContext = StaffAccessContext.Edit; } }