Ejemplo n.º 1
0
        private StaffDetail _populateValues(StaffDetail entity, StaffModel model)
        {
            if (null == entity)
            {
                entity = new StaffDetail();

                entity.ID       = model.ID;
                entity.StaffId  = model.StaffId;
                entity.SchoolId = model.SchoolId;
            }
            entity.ClassId          = model.ClassId;
            entity.DepartmentId     = model.DepartmentId;
            entity.PrimaryTagId     = model.PrimaryTagId;
            entity.ReportingEmailId = model.ReportingEmailId;
            entity.SectionId        = model.SectionId;
            entity.StaffMobileNo    = model.StaffMobileNo;
            entity.StaffName        = model.StaffName;
            entity.Address1         = model.Address1;
            entity.Address2         = model.Address2;
            entity.City             = model.City;
            entity.Country          = model.Country;
            entity.DateOfBirthh     = model.DateOfBirthh;
            entity.DepartmentId     = model.DepartmentId;
            entity.Gender           = model.Gender;
            entity.StateId          = model.StateId;
            entity.ZipCode          = model.ZipCode;

            return(entity);
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!LoggedInUser.IsAdmin)
            {
                Base.ShowError("Access Denied", "You do not have the required permission");
                return;
            }

            var item = new StaffDetail()
            {
                Id           = _id,
                DepartmentId = (comboDept.SelectedValue.ToString()),
                TitleId      = (comboTitle.SelectedValue.ToString()),
                Lastname     = txtSurname.Text.ToTitleCase(),
                Firstname    = txtFirstname.Text.ToTitleCase(),
                Othername    = txtOthername.Text.ToTitleCase(),
                Email        = txtEmail.Text.ToLower(),
                StaffNo      = txtStaffNo.Text.ToUpper(),
                PhoneNo      = txtPhoneNo.Text,
                IsAdmin      = checkIsAdmin.Checked,
                IsSuperAdmin = checkIsSystemAdmin.Checked
            };

            var validate = ValidateForm();

            if (validate == string.Empty)
            {
                AddOrUpdate(item);
            }
            else
            {
                Base.ShowInfo("Validation Failed", validate);
            }
        }
Ejemplo n.º 3
0
        private static void UpdateStaffGroups(StaffDetail detail, Staff staff, Predicate <StaffGroupSummary> p1, Predicate <StaffGroup> p2,
                                              IPersistenceContext context)
        {
            // create a helper to sync staff group membership
            CollectionSynchronizeHelper <StaffGroup, StaffGroupSummary> helper =
                new CollectionSynchronizeHelper <StaffGroup, StaffGroupSummary>(
                    delegate(StaffGroup group, StaffGroupSummary summary)
            {
                return(group.GetRef().Equals(summary.StaffGroupRef, true));
            },
                    delegate(StaffGroupSummary groupSummary, ICollection <StaffGroup> groups)
            {
                StaffGroup group = context.Load <StaffGroup>(groupSummary.StaffGroupRef, EntityLoadFlags.Proxy);
                group.AddMember(staff);
            },
                    delegate
            {
                // do nothing
            },
                    delegate(StaffGroup group, ICollection <StaffGroup> groups)
            {
                group.RemoveMember(staff);
            }
                    );

            helper.Synchronize(
                CollectionUtils.Select(staff.Groups, p2),
                CollectionUtils.Select(detail.Groups, p1));
        }
Ejemplo n.º 4
0
        // Retrieve Staff Details information from Database
        public static List <StaffDetail> RetrieveStaffDetail()
        {
            SQLConnection();
            MySqlDataReader    rdr     = null;
            List <StaffDetail> _staffs = new List <StaffDetail>();

            try
            {
                // Open the connection
                conn.Open();
                // 1. Instantiate a new command with a query and connection
                MySqlCommand cmd = new MySqlCommand("select id, given_name, family_name, title, campus, phone, room, email, photo, category from staff", conn);
                // 2. Call Execute reader to get query results
                rdr = cmd.ExecuteReader();
                // print the CategoryName of each record
                while (rdr.Read())
                {
                    StaffDetail _staffDetail = new StaffDetail(rdr.GetInt32(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), (Campus)Enum.Parse(typeof(Campus), rdr.GetString(4)), rdr.GetString(5), rdr.GetString(6), rdr.GetString(7), rdr.GetString(8), (Category)Enum.Parse(typeof(Category), rdr.GetString(9)));
                    //Console.WriteLine("Retrive from database: " + _staffDetail);
                    _staffs.Add(_staffDetail);
                }
            }
            finally
            {
                // close the reader
                CloseReader(rdr);
                // Close the connection
                CloseConnection(conn);
            }

            return(_staffs);
        }
        // GET: Staff/Delete/5
        public ActionResult Delete(StaffDetail staffDetail)
        {
            var d = instance.StaffDetails.Where(x => x.id == staffDetail.id).FirstOrDefault();

            instance.StaffDetails.Remove(d);
            instance.SaveChanges();
            return(RedirectToAction("allEmployee"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StaffDetail staffDetail = db.StaffDetails.Find(id);

            db.StaffDetails.Remove(staffDetail);
            db.SaveChanges();
            return(Content("<html><head><script>alert('Successfully Deleted'); window.location.href = '/StaffDetails/StaffDetails'</script></head></html>"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StaffDetail staffDetail = db.StaffDetails.Find(id);

            db.StaffDetails.Remove(staffDetail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public UpdateStaffRequest(StaffDetail staffDetail)
        {
            this.StaffDetail = staffDetail;

			// update all staff groups by default (eg assume operating in "admin" mode)
        	this.UpdateNonElectiveGroups = true;
        	this.UpdateElectiveGroups = true;
        }
Ejemplo n.º 9
0

        
 public ActionResult AddStaff([Bind(Include = "StaffId,Name,Gender,City,Experience,PhoneNumber,Salary,subject")] StaffDetail staffDetail)
 {
     if (ModelState.IsValid)
     {
         db.StaffDetails.Add(staffDetail);
         db.SaveChanges();
         return(Content("<html><head><script>alert('Successfully Registered'); window.location.href = '/StaffDetails/AddStaff'</script></head></html>"));
     }
     return(View(staffDetail));
 }
 public ActionResult Edit([Bind(Include = "StaffId,Name,Gender,City,Experience,PhoneNumber,Salary,subject")] StaffDetail staffDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(staffDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(Content("<html><head><script>alert('Successfully Updated'); window.location.href = '/StaffDetails/Index'</script></head></html>"));
     }
     return(View(staffDetail));
 }
 public ActionResult Create(StaffDetail staffDetail)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     instance.StaffDetails.Add(staffDetail);
     instance.SaveChanges();
     return(RedirectToAction("allEmployee"));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Called to handle the "delete" action, if supported.
        /// </summary>
        /// <param name="items"></param>
        /// <param name="deletedItems">The list of items that were deleted.</param>
        /// <param name="failureMessage">The message if there any errors that occurs during deletion.</param>
        /// <returns>True if items were deleted, false otherwise.</returns>
        protected override bool DeleteItems(IList <StaffSummary> items, out IList <StaffSummary> deletedItems, out string failureMessage)
        {
            failureMessage = null;
            deletedItems   = new List <StaffSummary>();

            foreach (StaffSummary item in items)
            {
                try
                {
                    Platform.GetService <IStaffAdminService>(
                        delegate(IStaffAdminService service)
                    {
                        // check if staff has associated user account
                        StaffDetail detail = service.LoadStaffForEdit(
                            new LoadStaffForEditRequest(item.StaffRef)).StaffDetail;
                        if (!string.IsNullOrEmpty(detail.UserName))
                        {
                            // ask if the account should be deleted too
                            if (this.Host.ShowMessageBox(
                                    string.Format(SR.MessageConfirmDeleteAssociatedUserAccount, detail.UserName), MessageBoxActions.YesNo)
                                == DialogBoxAction.Yes)
                            {
                                Platform.GetService <IUserAdminService>(
                                    delegate(IUserAdminService userAdminService)
                                {
                                    userAdminService.DeleteUser(new DeleteUserRequest(detail.UserName));
                                });
                            }
                            else
                            {
                                // not deleting user, but we should update user's display name
                                Platform.GetService <IUserAdminService>(
                                    delegate(IUserAdminService userAdminService)
                                {
                                    LoadUserForEditResponse editResponse = userAdminService.LoadUserForEdit(new LoadUserForEditRequest(detail.UserName));
                                    UserDetail userDetail  = editResponse.UserDetail;
                                    userDetail.DisplayName = null;

                                    userAdminService.UpdateUser(new UpdateUserRequest(userDetail));
                                });
                            }
                        }
                        service.DeleteStaff(new DeleteStaffRequest(item.StaffRef));
                    });

                    deletedItems.Add(item);
                }
                catch (Exception e)
                {
                    failureMessage = e.Message;
                }
            }

            return(deletedItems.Count > 0);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Create Staff
 /// </summary>
 /// <param name="staff"></param>
 /// <returns></returns>
 public string CraeteStaff(StaffDetail staff)
 {
     try
     {
         _dbContext.StaffDetails.Add(staff);
         _dbContext.SaveChanges();
         return("Added");
     }
     catch (Exception ex)
     {
         return("Exception while Creating Staff" + ex.Source);
     }
 }
 public ActionResult Edit([Bind(Include = "Id,StaffId,StaffName,Department,PrimaryTagId,ReportingEmailId,StaffMobileNo,ClassId,SectionId")] StaffDetail staffDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(staffDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ClassId      = new SelectList(db.Classes, "Id", "Name", staffDetail.ClassId);
     ViewBag.PrimaryTagId = new SelectList(db.PrimaryTags, "Id", "TagId", staffDetail.PrimaryTagId);
     ViewBag.SectionId    = new SelectList(db.Sections, "Id", "Name", staffDetail.SectionId);
     return(View(staffDetail));
 }
        public ActionResult Edit(StaffDetail staffDetail)
        {
            var orignalRecord = (from m in instance.StaffDetails where m.id == staffDetail.id select m).First();

            if (!ModelState.IsValid)
            {
                return(View(orignalRecord));
            }
            instance.Entry(orignalRecord).CurrentValues.SetValues(staffDetail);

            instance.SaveChanges();
            return(RedirectToAction("allEmployee"));
        }
        // GET: StaffDetails/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StaffDetail staffDetail = db.StaffDetails.Find(id);

            if (staffDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(staffDetail));
        }
        // get staff details by staff ID
        public static StaffDetail getStaffDetail(int _staffId)
        {
            StaffDetail _staffDetail = null;
            //use linq to filter here
            var _staffDetailList = DatabaseAdapter.RetrieveStaffDetail();
            var list             = from item in _staffDetailList where item.Id == _staffId select item;

            foreach (var item in list)
            {
                _staffDetail = item;
                Console.WriteLine(item);
            }
            return(_staffDetail);
        }
Ejemplo n.º 19
0
        public void StaffManagementController_CraeteStaff()
        {
            var mockRepo = new Mock <IRepository>();
            var detail   = new StaffDetail {
                Name = "Shivam", HoursAvailable = 8, DateCreated = DateTime.Now, IsAvailable = true
            };

            mockRepo.Setup(repo => repo.CraeteStaff(detail)).Returns("Added");
            var controller = new StaffManagementController(mockRepo.Object);

            var result1 = controller.CreateStaff(detail);
            var result  = result1 as OkResult;

            Assert.AreEqual(result.StatusCode, 200);
        }
Ejemplo n.º 20
0
        private void AddOrUpdate(StaffDetail item)
        {
            var saveItem = _id == ""
                ? _repo.AddStaff(item)
                : _repo.UpdateStaff(item);

            if (saveItem == string.Empty)
            {
                Base.ShowSuccess("Success", "Staff saved successfully");
                this.Close();
            }
            else
            {
                Base.ShowError("Failed", saveItem);
            }
        }
Ejemplo n.º 21
0
        public void StaffManagementController_GetActiveStaffList()
        {
            var mockRepo = new Mock <IRepository>();
            var detail   = new StaffDetail {
                Name = "Shivam", DateCreated = DateTime.Now, HoursAvailable = 8, IsAvailable = true
            };

            mockRepo.Setup(repo => repo.GetActiveStaff()).Returns(new List <StaffDetail> {
                detail
            });
            var controller = new StaffManagementController(mockRepo.Object);

            var result = controller.GetActiveStaffList() as JsonResult;


            Assert.NotNull(result.Value);
        }
        // GET: StaffDetails/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StaffDetail staffDetail = db.StaffDetails.Find(id);

            if (staffDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ClassId      = new SelectList(db.Classes, "Id", "Name", staffDetail.ClassId);
            ViewBag.PrimaryTagId = new SelectList(db.PrimaryTags, "Id", "TagId", staffDetail.PrimaryTagId);
            ViewBag.SectionId    = new SelectList(db.Sections, "Id", "Name", staffDetail.SectionId);
            return(View(staffDetail));
        }
        private UserLookupData GetUserForStaff(StaffDetail staff)
        {
            UserLookupData user = null;

            if (!string.IsNullOrEmpty(staff.UserName))
            {
                // If this staff is associated with an user, get the most updated user using IUserAdminService
                if (this.IsUserAdmin)
                {
                    Platform.GetService <IUserAdminService>(
                        delegate(IUserAdminService service)
                    {
                        ListUsersRequest request   = new ListUsersRequest();
                        request.UserName           = staff.UserName;
                        request.ExactMatchOnly     = true;
                        ListUsersResponse response = service.ListUsers(request);
                        UserSummary summary        = CollectionUtils.FirstElement(response.Users);

                        // If there is no return user, it means that the user was deleted without updating staff.
                        user = summary == null ? null : new UserLookupData(summary.UserName);
                    });

                    if (user == null)
                    {
                        _userNameNoLongerExist = staff.UserName;

                        // The user no longer exist, delete user name.
                        staff.UserName = null;

                        // Nevertheless, display this info.
                        user = new UserLookupData(_userNameNoLongerExist);
                    }
                }
                else
                {
                    // if user is not a UserAdmin, don't hit the server, use the data we already have.
                    // unfortunately, we cannot detect the case where user is deleted without staff updated.
                    user = new UserLookupData(staff.UserName);
                }
            }

            return(user);
        }
        public IActionResult CreateStaff(StaffDetail staff)
        {
            if (staff != null)
            {
                staff.IsAvailable = true;

                var res = _repo.CraeteStaff(staff);
                if (res == "Added")
                {
                    return(Ok());
                }
                else
                {
                    return(StatusCode(500, "Internal Server Error. Something went Wrong!"));
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 25
0
        public string AddStaff(StaffDetail newStaff)
        {
            try
            {
                if (_context.Staff.Any(a => a.StaffNo == newStaff.StaffNo || a.Email == newStaff.Email && !a.IsDeleted))
                {
                    return("Staff with this Staff number or Email address exists");
                }

                var defaultPwd = _context.SystemSettings.First().UserDefaultPassword;

                newStaff.Id       = Guid.NewGuid().ToString();
                newStaff.Password = defaultPwd;
                _context.Staff.Add(newStaff);
                return(_context.SaveChanges() > 0 ? "" : "Staff could not be added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Called to handle the "toggle activation" action, if supported
        /// </summary>
        /// <param name="items">A list of items to edit.</param>
        /// <param name="editedItems">The list of items that were edited.</param>
        /// <returns>True if items were edited, false otherwise.</returns>
        protected override bool UpdateItemsActivation(IList <StaffSummary> items, out IList <StaffSummary> editedItems)
        {
            List <StaffSummary> results = new List <StaffSummary>();

            foreach (StaffSummary item in items)
            {
                Platform.GetService <IStaffAdminService>(
                    delegate(IStaffAdminService service)
                {
                    StaffDetail detail = service.LoadStaffForEdit(
                        new LoadStaffForEditRequest(item.StaffRef)).StaffDetail;
                    detail.Deactivated   = !detail.Deactivated;
                    StaffSummary summary = service.UpdateStaff(
                        new UpdateStaffRequest(detail)).Staff;

                    results.Add(summary);
                });
            }

            editedItems = results;
            return(true);
        }
Ejemplo n.º 27
0
        public string UpdateStaff(StaffDetail staff)
        {
            var oldStaff = _context.Staff.SingleOrDefault(a => a.Id == staff.Id && !a.IsDeleted);

            if (oldStaff == null)
            {
                return("Staff not found");
            }

            if (_context.Staff.Any(a => (a.StaffNo == staff.StaffNo || a.Email == staff.Email && !a.IsDeleted) && a.Id != staff.Id))
            {
                return("Staff with this Staff number or Email address exists");
            }

            oldStaff.Email        = staff.Email.ToLower();
            oldStaff.Firstname    = staff.Firstname.ToTitleCase();
            oldStaff.IsAdmin      = staff.IsAdmin;
            oldStaff.IsSuperAdmin = staff.IsSuperAdmin;
            oldStaff.Lastname     = staff.Lastname.ToTitleCase();
            oldStaff.Othername    = staff.Othername.ToTitleCase();
            oldStaff.StaffNo      = staff.StaffNo;
            oldStaff.TitleId      = staff.TitleId;
            oldStaff.StaffNo      = staff.StaffNo;
            oldStaff.PhoneNo      = staff.PhoneNo;
            oldStaff.DepartmentId = staff.DepartmentId;

            if (_context.SaveChanges() > 0)
            {
                if (LoggedInUser.UserId == staff.Id)
                {
                    LoggedInUser.IsSuperAdmin = staff.IsSuperAdmin;
                    LoggedInUser.IsAdmin      = staff.IsAdmin;
                }
                return("");
            }

            return("No changes made");
        }
 /// <summary>
 /// Formats the staff name and role similar to "Test, Name (Role)" with the name formatted according to the specified format string.
 /// </summary>
 /// <remarks>
 /// Valid format specifiers are as follows:
 ///     %F - full family name
 ///     %f - family name initial
 ///     %G - full given name
 ///     %g - given name initial
 ///     %M - full middle name
 ///     %m - middle initial
 /// </remarks>
 /// <param name="staff"></param>
 /// <param name="format"></param>
 /// <returns></returns>
 public static string Format(StaffDetail staff, string format)
 {
     return(string.Format("{0} ({1})", PersonNameFormat.Format(staff.Name, format), staff.StaffType.Value));
 }
 /// <summary>
 /// Formats the staff name and role similar to "Test, Name (Role)".  Name is formatted according to the default person name format as
 /// specified in <see cref="FormatSettings"/>
 /// </summary>
 /// <param name="staff"></param>
 /// <returns></returns>
 public static string Format(StaffDetail staff)
 {
     return(Format(staff, FormatSettings.Default.PersonNameDefaultFormat));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public StaffDetailsEditorComponent(List <EnumValueInfo> staffTypeChoices, List <EnumValueInfo> sexChoices)
 {
     _staffDetail      = new StaffDetail();
     _staffTypeChoices = staffTypeChoices;
     _sexChoices       = sexChoices;
 }
        public override void Start()
        {
            Platform.GetService <IStaffAdminService>(
                delegate(IStaffAdminService service)
            {
                LoadStaffEditorFormDataResponse formDataResponse = service.LoadStaffEditorFormData(new LoadStaffEditorFormDataRequest());

                this.ValidationStrategy = new AllComponentsValidationStrategy();

                if (_isNew)
                {
                    _staffDetail           = new StaffDetail();
                    _staffDetail.StaffType = CollectionUtils.FirstElement(formDataResponse.StaffTypeChoices);
                }
                else
                {
                    LoadStaffForEditResponse response = service.LoadStaffForEdit(new LoadStaffForEditRequest(_staffRef));
                    _staffRef    = response.StaffDetail.StaffRef;
                    _staffDetail = response.StaffDetail;
                }

                _originalStaffUserName = _staffDetail.UserName;

                _detailsEditor = new StaffDetailsEditorComponent(formDataResponse.StaffTypeChoices, formDataResponse.SexChoices)
                {
                    StaffDetail = _staffDetail
                };
                this.Pages.Add(new NavigatorPage("Staff", _detailsEditor));

                _phoneNumbersSummary = new PhoneNumbersSummaryComponent(formDataResponse.PhoneTypeChoices)
                {
                    ReadOnly = !CanModifyStaffProfile,
                    SetModifiedOnListChange = true,
                    Subject = _staffDetail.TelephoneNumbers
                };
                this.Pages.Add(new NavigatorPage("Staff/Phone Numbers", _phoneNumbersSummary));

                _addressesSummary = new AddressesSummaryComponent(formDataResponse.AddressTypeChoices)
                {
                    ReadOnly = !CanModifyStaffProfile,
                    SetModifiedOnListChange = true,
                    Subject = _staffDetail.Addresses
                };
                this.Pages.Add(new NavigatorPage("Staff/Addresses", _addressesSummary));

                _emailAddressesSummary = new EmailAddressesSummaryComponent
                {
                    ReadOnly = !CanModifyStaffProfile,
                    SetModifiedOnListChange = true,
                    Subject = _staffDetail.EmailAddresses
                };
                this.Pages.Add(new NavigatorPage("Staff/Email Addresses", _emailAddressesSummary));



                // allow modification of non-elective groups only iff the user has StaffGroup admin permissions
                this.Pages.Add(new NavigatorPage("Staff/Groups/Non-elective", _nonElectiveGroupsEditor = new StaffNonElectiveStaffGroupEditorComponent(_staffDetail.Groups, formDataResponse.StaffGroupChoices, !CanModifyNonElectiveGroups)));
                this.Pages.Add(new NavigatorPage("Staff/Groups/Elective", _electiveGroupsEditor        = new StaffElectiveStaffGroupEditorComponent(_staffDetail.Groups, formDataResponse.StaffGroupChoices, !CanModifyStaffProfile)));
            });

            // instantiate all extension pages
            _extensionPages = new List <IStaffEditorPage>();
            foreach (IStaffEditorPageProvider pageProvider in new StaffEditorPageProviderExtensionPoint().CreateExtensions())
            {
                _extensionPages.AddRange(pageProvider.GetPages(new EditorContext(this)));
            }

            // add extension pages to navigator
            // the navigator will start those components if the user goes to that page
            foreach (IStaffEditorPage page in _extensionPages)
            {
                this.Pages.Add(new NavigatorPage(page.Path, page.GetComponent()));
            }

            base.Start();
        }
Ejemplo n.º 32
0
 public AddStaffRequest(StaffDetail staffDetail)
 {
     this.StaffDetail = staffDetail;
 }
Ejemplo n.º 33
0
 public LoadStaffForEditResponse(StaffDetail staffDetail)
 {
     this.StaffDetail = staffDetail;
 }