Ejemplo n.º 1
0
        public IActionResult OnGet(int?id)
        {
            Console.WriteLine("Delete page : " + id);
            string DbConnection = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Staffs;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            SqlConnection conn = new SqlConnection(DbConnection);

            conn.Open();

            using (SqlCommand command = new SqlCommand())
            {
                command.Connection  = conn;
                command.CommandText = "SELECT * FROM Staffs WHERE StaffID = @SID";
                command.Parameters.AddWithValue("@SID", id);

                SqlDataReader reader = command.ExecuteReader();
                Models.Staff  rec    = new Models.Staff(); //a local var to hold a record temporarily
                while (reader.Read())
                {
                    rec.Id               = reader.GetInt32(0);
                    rec.StaffID          = reader.GetString(1);
                    rec.StaffFname       = reader.GetString(2);
                    rec.StaffLname       = reader.GetString(3);
                    rec.StaffSex         = reader.GetString(4);
                    rec.StaffEmail       = reader.GetString(5);
                    rec.Stafftype        = reader.GetString(6);
                    rec.Staffnationality = reader.GetString(7);
                    rec.Staffpassword    = reader.GetString(8);
                }
            }

            conn.Close();

            return(Page());
        }
Ejemplo n.º 2
0
        public void LoadInformation()
        {
            staff = App.StaffDatabase.GetStaffById(Convert.ToInt32(App.SettingsDatabase.GetSetting("AssignedStaffId").Value));

            AnnualLeaveBalance.Text     = staff.AnnualLeaveBalance.ToString();
            AnnualLeaveEntitlement.Text = "Your annual leave entitlement is " + staff.AnnualLeaveAllowance.ToString() + " days, excluding English bank holidays, from Janurary 1st to December 31st.";
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 加载父级菜单
        /// </summary>
        public void ParentMenu()
        {
            Models.Staff staffinfo         = (Models.Staff)Session["loginuser"];
            List <Models.v_staffmune> menu = DB.v_staffmune.Where(o => o.staffid.Equals(staffinfo.Id) && o.Type == 0 && o.ParentId == null).ToList();

            ViewData.Model = menu;
        }
Ejemplo n.º 4
0
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     else
     {
         staff = StudentDatabase.Login(LoginStaff.Username, LoginStaff.Password);
         if (staff.staffId != 0)
         {
             if (staff.Administration == true) // hvis brugeren hentet fra SQL er i administration, så sættes det til True i session.
             {
                 HttpContext.Session.SetString("Administration", "TRUE");
             }
             if (staff.Teacher == true) // hvis brugeren hentet fra SQL er underviser, så sættes det til True i session.
             {
                 HttpContext.Session.SetString("Teacher", "TRUE");
             }
             HttpContext.Session.SetString("LoggedIn", "TRUE");
             return(RedirectToPage("/Students/StudentList")); // Efter login foretages redirect til studentlist.
         }
         else
         {
             TempData["LoginMessage"] = "Invalid login"; // Hvis login fejler, sættes en midlertidig besked som vises på login siden bagefter.
             return(Page());
         }
     }
 }
Ejemplo n.º 5
0
        public ActionResult Create(FormCollection collection)
        {
            if (SUserRole() != "Customer" && SUserRole() != null)
            {
                ViewBag.displayMenu = "Yes";
            }
            try
            {
                // TODO: Add insert logic here
                Staff newStaff = new Models.Staff();
                newStaff.Address   = Request.Form["Address"];
                newStaff.AspId     = Request.Form["AspId"];
                newStaff.Contact   = Request.Form["Contact"];
                newStaff.Email     = Request.Form["Email"];
                newStaff.Position  = Request.Form["ddlPosition"];
                newStaff.StaffName = Request.Form["StaffName"];
                newStaff.UserName  = Request.Form["UserName"];
                db.Staffs.Add(newStaff);
                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                string error  = e.InnerException.Message;
                string error2 = e.InnerException.InnerException.Message;
                return(View());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 加载子级菜单
        /// </summary>
        /// <param name="parentmeunid">与parentid对应的父子级关系id</param>
        /// <returns></returns>
        public ActionResult ChildMenu(string parentmeunid)
        {
            Models.Staff staffinfo         = (Models.Staff)Session["loginuser"];
            List <Models.v_staffmune> menu = DB.v_staffmune.Where(o => o.staffid.Equals(staffinfo.Id) && o.ParentId.ToString().Equals(parentmeunid)).ToList();

            return(Json(menu));
        }
Ejemplo n.º 7
0
        public ActionResult StaffEditSaveChanges(Models.Staff editedStaffDetails)
        {
            // Fetch the old data of staff from database
            var oldData = _context.Staffs.FirstOrDefault(u => u.Id == editedStaffDetails.Id);

            // Setting up new data
            if (oldData != null)
            {
                oldData.Address = editedStaffDetails.Address;
                oldData.Email   = editedStaffDetails.Email;
                oldData.Name    = editedStaffDetails.Name;
                oldData.Phone   = editedStaffDetails.Phone;
                oldData.Surname = editedStaffDetails.Surname;

                // Commit new changes to database
                _context.SaveChanges();

                // Set the success message
                TempData["StaffDetailsEditedSuccessfully"] = "Staff details edited successfully";
                return(RedirectToAction("Index", "Staff"));
            }

            TempData["StaffDetailsEditFailed"] = "Cannot edit staff details.";
            return(RedirectToAction("Index", "Staff"));
        }
        public ActionResult submitedStaff(Models.Staff formData)
        {
            var model = My_Locker_V2.Classes.MyCommonUtilities.GetIgrejas();

            if (formData.Email.Contains("@"))
            {
                var ID = context.Database.SqlQuery <Staff>("SELECT ID FROM Staff WHERE Email = '" + formData.Email.ToLower() + "'").ToList();

                if (ID.Count() == 0)
                {
                    try
                    {
                        context.Database.ExecuteSqlCommand("INSERT INTO dbo.Staff(Email,_Password,igrejaId) VALUES ('" + formData.Email.ToLower() + "','" + My_Locker_V2.Classes.MyCommonUtilities.Encrypt(formData.C_Password) + "','" + formData.igrejaId + "')");
                    }
                    catch (Exception er) { }
                }
                else
                {
                    ModelState.AddModelError("Email", "Email Introduzido Já Em Uso");
                    return(PartialView("_addStaff", model));
                }
            }
            else
            {
                ModelState.AddModelError("Email", "Email Introduzido Incorreto");
                return(PartialView("_addStaff", model));
            }



            return(View());
        }
Ejemplo n.º 9
0
 public ActionResult Index()
 {
     Models.Staff staffinfo = (Models.Staff)Session["loginuser"];
     ViewBag.Name = staffinfo.Name;
     ParentMenu();
     return(View());
 }
Ejemplo n.º 10
0
        public async Task <Models.Staff> CreateStaffMember(Models.Staff member)
        {
            await _unitOfWork.StaffMembers.AddAsync(member);

            await _unitOfWork.CommitAsync();

            return(member);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Default constructor for client, so no null values are returned on initial views.
        /// </summary>
        public Client()
        {
            raceID                     = 1;
            ethnicityID                = 1;
            clientStatusID             = 1;
            primaryLanguageID          = 1;
            schoolInfoID               = 1;
            communicationPreferencesID = 1;
            sexID              = 1;
            officeID           = 1;
            memberTypeID       = 1;
            altID              = "";
            accountingSystemID = "";
            TKIDcaseNumber     = 0;

            // Referral
            referralSource = "";
            agencyFrom     = "";

            // Demographics
            firstName     = "";
            middleInitial = "";
            lastName      = "";
            fullName      = "";
            ageInMonths   = 0;
            ssn           = 0;

            // Address
            clientAddress = new Address();

            // Contact
            phone = new AdditionalContactInfoModel();

            clientDiagnosis = new List <Diagnosis>();

            clientFamily = new List <Family>();
            guardian     = new Family();

            clientPhysicians = new List <Physician>();

            clientStaff        = new List <Staff>();
            intakeCoordinator  = new Models.Staff();
            serviceCoordinator = new Staff();
            caseManager        = new Staff();

            clientInsurance = new List <ClientInsurance>();

            clientComments = new List <Comments>();

            clientReferrals = new List <Referral>();

            caseManager = new Staff();

            insertClientComplete        = false;
            insertClientDetailsComplete = false;
            insertFamilyComplete        = false;
            insertReferralComplete      = false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 用来获取用户登录信息
        /// </summary>
        /// <param name="loginOk">是否成功登录</param>
        /// <param name="message">提示信息</param>
        /// <param name="staffInfo">用户信息</param>
        /// <returns></returns>
        public ActionResult ReturnJosn(bool loginOk, string message, Models.Staff staffInfo)
        {
            var result = new
            {
                LoginOk   = loginOk,
                Message   = message,
                StaffInfo = staffInfo
            };

            return(Json(result));
        }
Ejemplo n.º 13
0
 public ActionResult AddStaffInfo(Models.Staff staffinfo)
 {
     staffinfo.Id         = Guid.NewGuid();
     staffinfo.CreateTime = DateTime.Now;
     staffinfo.UpdateTime = DateTime.Now;
     staffinfo.IsHSEGroup = false;
     staffinfo.Sex        = Request.Form[3] == (0).ToString() ? false : true;
     staffinfo.Password   = HelperTools.EncryptHelper.Encode("svse");//默认密码(svse)
     DB.Staff.Add(staffinfo);
     return(Content(DB.SaveChanges() > 0 ? "T" : "F"));
 }
Ejemplo n.º 14
0
        internal static Models.Staff mapStaff(Data.Staff ent, Models.Staff mdl = null)
        {
            if (ent == null) return mdl;
            if (mdl == null) mdl = new Models.Staff();

            mdl.ID = new Models.StaffID(ent.StaffID);
            mdl.FirstName = ent.FirstName;
            mdl.LastName = ent.LastName;

            return mdl;
        }
Ejemplo n.º 15
0
        //------------------------------------------------------TRAINING VIDEO----------------------------------------------------------//

        public ActionResult TrainingVideoDetail()
        {
            Staff s = new Models.Staff();

            ViewBag.dts = s.selectall();

            VideoCategory vc = new Models.VideoCategory();

            ViewBag.dtvc = vc.selectall();
            return(View());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 查看已删除的员工档案
        /// </summary>
        /// <returns>返回列表视图</returns>
        public ActionResult StaffViewDeleted()
        {
            IStaffBLL bLL = new StaffBLL();

            IOrgBLL orgBLL = new OrgBLL();

            IOccupationBLL occupationBLL = new OccupationBLL();

            List <Staff> staffList = bLL.GetAllStaffDeleted();

            List <Models.Staff> staffListView = new List <Models.Staff>();

            if (staffList != null)
            {
                foreach (var staff in staffList)
                {
                    Models.Staff tempStaff = new Models.Staff
                    {
                        Id = staff.Id,
                        StaffFileNumber = staff.StaffFileNumber,
                        StaffName       = staff.StaffName,
                        FileState       = staff.FileState,
                        IsDel           = staff.IsDel
                    };
                    ThirdOrg  thirdOrg  = orgBLL.GetThirdOrgById(staff.ThirdOrgId);
                    SecondOrg secondOrg = orgBLL.GetSecondOrgById(thirdOrg.ParentOrgId);
                    FirstOrg  firstOrg  = orgBLL.GetFirstOrgById(secondOrg.ParentOrgId);

                    tempStaff.FirstOrg = new Models.FirstOrg {
                        Id = firstOrg.Id, OrgLevel = firstOrg.OrgLevel, OrgName = firstOrg.OrgName
                    };
                    tempStaff.SecondeOrg = new Models.SecondeOrg {
                        Id = secondOrg.Id, OrgName = secondOrg.OrgName, OrgLevel = secondOrg.OrgLevel, ParentOrg = tempStaff.FirstOrg
                    };
                    tempStaff.ThirdOrg = new Models.ThirdOrg {
                        Id = thirdOrg.Id, ParentOrg = tempStaff.SecondeOrg, OrgLevel = thirdOrg.OrgLevel, OrgName = thirdOrg.OrgName
                    };

                    OccupationName occupationName = occupationBLL.GetOccupationNameById(staff.OccId);

                    tempStaff.OccupationName = new Models.OccupationName {
                        Id = occupationName.Id, Name = occupationName.Name
                    };

                    staffListView.Add(tempStaff);
                }
            }

            ViewData["staffListView"] = staffListView;

            return(View());
        }
Ejemplo n.º 17
0
        public ActionResult Amend(Models.Staff smodel)
        {
            if (ModelState.IsValid)
            {
                StaffDAL.UpdateEmployeeDetails(smodel);

                return(Redirect("Home"));
            }
            else
            {
                return(Redirect("Home"));
            }
        }
Ejemplo n.º 18
0
        public ActionResult TeacherAdd(Models.Staff data)
        {
            // Add it to context and commit it to DB
            data.Password = "******";

            _context.Staffs.Add(data);

            _context.SaveChanges();

            // Set the success message
            TempData["StaffAddedMessage"] = "Staff added successfully";

            return(RedirectToAction("Index", "Staff"));
        }
Ejemplo n.º 19
0
 public StaffEdit(DialogMode mode, int?staffID, IDialogService dialogService, IMessageBoxService messageService)
     : base(mode, dialogService, messageService)
 {
     SubTitle = "Сотрудника";
     if (staffID.HasValue)
     {
         _data = _dc.Staffs.SingleOrDefault(x => x.ID == staffID);
     }
     else
     {
         _data = new Models.Staff();
         _dc.Staffs.Add(_data);
     };
     _staffServices = new List <object>(_data.Services.Cast <object>().ToList());
 }
Ejemplo n.º 20
0
        // GET: Users
        public ActionResult Index()
        {
            Staff s = Session["user"] as Staff;

            var baseCtrler = DependencyResolver.Current.GetService <BaseController>();

            Models.Staff user = Session["user"] as Models.Staff;
            //Session["Job"] = db.Job.Where(r => r.Id == user.JobId);
            ViewBag.username = user.Name;
            List <Models.SystemResourceModule> Sredata = baseCtrler.GetSystemResources(user.Id);

            ViewBag.Parent = Sredata.Where(r => r.ParentId == null);
            ViewBag.Chiren = Sredata.Where(r => r.ParentId != null);
            return(View());
        }
Ejemplo n.º 21
0
        public ActionResult TrainingVideoEdit(int id)
        {
            TrainingVideo c = new TrainingVideo();

            c.TrainingVideoID = id;
            c.SelectByID();


            Staff s = new Models.Staff();

            ViewBag.dts = s.selectall();

            VideoCategory vc = new Models.VideoCategory();

            ViewBag.dtvc = vc.selectall();

            return(View(c));
        }
Ejemplo n.º 22
0
 public ActionResult UpdateStaffInfo(Models.Staff staffinfo)
 {
     Models.Staff obj = DB.Staff.FirstOrDefault(o => o.Id.Equals(staffinfo.Id));
     obj.No          = staffinfo.No;
     obj.Name        = staffinfo.Name;
     obj.BirthDay    = staffinfo.BirthDay;
     obj.Sex         = Request.Form[4] == (0).ToString() ? false : true;
     obj.NativePlace = staffinfo.NativePlace;
     obj.Address     = staffinfo.Address;
     obj.Tel         = staffinfo.Tel;
     obj.Email       = staffinfo.Email;
     obj.OrgID       = staffinfo.OrgID;
     obj.JobId       = staffinfo.JobId;
     obj.Status      = staffinfo.Status;
     obj.UpdateTime  = DateTime.Now;
     DB.Staff.Attach(obj);
     DB.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     return(Content(DB.SaveChanges() > 0 ? "T" : "F"));
 }
Ejemplo n.º 23
0
        }                                       // Er nødt til at kolde Models.Staff da jeg har været så klog at kalde mappen i pages staff også.

        public IActionResult OnGet(int staffId)
        {
            if (HttpContext.Session.GetString("Administration") == "TRUE") // Der foretages login tjek
            {
                Staff = StudentDatabase.GetStaffById(staffId);             // Staff hentes fra databasen
                if (Staff == null)                                         // Hvis der ikke kunne findes en ansat redirectes man tilbage til stafflist.
                {
                    return(RedirectToPage("./StaffList"));
                }
                else // Hvis der blev fundet en ansat vises detail siden.
                {
                    return(Page());
                }
            }
            else
            {
                return(RedirectToPage("./StaffLogin"));
            }
        }
Ejemplo n.º 24
0
        public ActionResult GetData()
        {
            string name     = Request["name"].ToString();
            string password = Request["pwd"].ToString();
            string flag     = "";
            var    list     = db.Staff.Where(u => u.Name == name && u.Password == password).ToList();

            Models.Staff s = list.FirstOrDefault(); //将泛型集合转成实体对象

            if (list.Count > 0)                     //当集合的成员大于0时候,说明登录成功
            {
                Session["user"] = s;
                //return RedirectToAction("Index", "Users");//跳转到主页面
                return(Json(s.Name, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(flag, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 25
0
        public ActionResult Login(string no, string pwd)
        {
            //pwd = HelperTools.EncryptHelper.Encode(pwd);

            Models.Staff staffInfo = DB.Staff.FirstOrDefault(o => o.No.Equals(no) && o.Password.Equals(pwd));

            if (string.IsNullOrEmpty(no) || string.IsNullOrEmpty(pwd))
            {
                return(ReturnJosn(false, "账号密码不能为空!", staffInfo));
            }
            else if (staffInfo == null)
            {
                return(ReturnJosn(false, "密码错误!", staffInfo));
            }
            else
            {
                Session["loginuser"] = staffInfo;
                return(ReturnJosn(false, "登录成功!", staffInfo));
            }
        }
        public ActionResult UpdatePwd(string OldPassword, string NewPassword)
        {
            Models.Staff staffinfo = (Models.Staff)Session["loginuser"];
            OldPassword = HelperTools.EncryptHelper.Encode(OldPassword);
            Models.Staff info = DB.Staff.FirstOrDefault(o => o.Password == OldPassword);

            if (info == null)
            {
                var json = new
                {
                    Error   = false,
                    Message = "原密码错误!",
                };
                return(Json(json));
            }
            else
            {
                Models.Staff staff = DB.Staff.FirstOrDefault(o => o.No == staffinfo.No);
                staff.Password = HelperTools.EncryptHelper.Encode(NewPassword);
                UpdateModel(staff);
                int rs = DB.SaveChanges();
                if (rs > 0)
                {
                    var json = new
                    {
                        Error   = true,
                        Message = "修改成功! 登录信息已经过期!",
                    };
                    return(Json(json));
                }
                else
                {
                    var json = new
                    {
                        Error   = false,
                        Message = "修改失败!",
                    };
                    return(Json(json));
                }
            }
        }
Ejemplo n.º 27
0
        public static OfficeStaff OfficeStaff(Models.Staff entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var s = new OfficeStaff();

            s.Active          = entity.StaffActive;
            s.DateCreated     = entity.DateCreated;
            s.DateCreated     = entity.DateCreated;
            s.Email           = entity.StaffPrimaryEmail;
            s.FirstName       = entity.StaffFirstName;
            s.HireDate        = entity.StaffHireDate;
            s.ID              = entity.ID;
            s.LastName        = entity.StaffLastName;
            s.Phone           = entity.StaffPrimaryPhone;
            s.TerminationDate = entity.StaffTerminatedDate;

            return(s);
        }
Ejemplo n.º 28
0
 public IActionResult OnGet(int?staffId)
 {
     if (HttpContext.Session.GetString("Administration") == "TRUE") // Der foretages login tjek
     {
         if (staffId.HasValue)                                      // Hvis der koms staffId med hentes staff fra StudentDB
         {
             staff = StudentDatabase.GetStaffById(staffId.Value);
         }
         else // Hvis ikke oprettes et nyt staff objekt
         {
             staff = new Models.Staff();
         }
         if (staff == null) // Hvis staff er null på dette tidspunkt sendes man til notfound siden.
         {
             return(RedirectToPage("/NotFound"));
         }
         return(Page());
     }
     else
     {
         return(RedirectToPage("./StaffLogin"));
     }
 }
Ejemplo n.º 29
0
        public IActionResult OnGet()
        {
            string        DbConnection = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Staffs;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection conn         = new SqlConnection(DbConnection);

            conn.Open();

            using (SqlCommand command = new SqlCommand())
            {
                command.Connection  = conn;
                command.CommandText = @"SELECT * FROM Staffs ORDER BY StaffFname"; // try order by Name

                SqlDataReader reader = command.ExecuteReader();

                RestaurantProject = new List <Models.Staff>();
                // Call Read before accessing data.
                while (reader.Read())                           //keep reading while there is a record
                {
                    Models.Staff rec = new Models.Staff();      //a local var to hold a record temporarily
                    rec.Id               = reader.GetInt32(0);
                    rec.StaffID          = reader.GetString(1); //make sure the data type is matched
                    rec.StaffFname       = reader.GetString(2);
                    rec.StaffLname       = reader.GetString(3);
                    rec.StaffSex         = reader.GetString(4);
                    rec.StaffEmail       = reader.GetString(5);
                    rec.Stafftype        = reader.GetString(6);
                    rec.Staffnationality = reader.GetString(7);


                    RestaurantProject.Add(rec); //the temporary var of rec which consists of a record is added to the the list
                }

                // Call Close when done reading.
                reader.Close();
            }
            return(Page());//return to the page after the result is obtained
        }
        private void btnCreateUser_Click(object sender, EventArgs e)
        {
            string names, phone, email, address, natid, np, cp;
            int    level;

            names   = txtNames.Text;
            phone   = txtPhone.Text;
            email   = txtEmail.Text;
            natid   = txtNationalId.Text;
            np      = txtNP.Text;
            cp      = txtCP.Text;
            level   = comboBox1.SelectedIndex + 1;
            address = txtAddress.Text;
            string error = "";

            if (names.Trim().Equals(""))
            {
                error += "\n.Names";
            }
            if (phone.Trim().Equals(""))
            {
                error += "\n.Phone";
            }
            if (email.Trim().Equals(""))
            {
                error += "\n.Email";
            }
            if (address.Trim().Equals(""))
            {
                error += "\n.Address";
            }
            if (natid.Trim().Equals(""))
            {
                error += "\n.NationalId";
            }
            else
            {
                try
                {
                    Convert.ToInt32(natid);
                }
                catch
                {
                    error += "\n.Invalid NationalId";
                }
            }

            if (np.Trim().Equals(""))
            {
                error += "\n.New Password";
            }

            if (cp.Trim().Equals(""))
            {
                error += "\n.Confirm Password";
            }
            else if (!cp.Equals(np))
            {
                error += "\n.Password Do Not Match";
            }

            if (comboBox1.Text.Trim().Equals(""))
            {
                error += "\n.Select A Level";
            }
            if (picUserPhoto.Image == null)
            {
                error += "\n.User Photo";
            }
            if (error.Trim().Equals(""))
            {
                Models.Staff user = new Models.Staff();

                user.Names      = names;
                user.Phone      = phone;
                user.Email      = email;
                user.Address    = address;
                user.NationalId = natid;
                user.Password   = cp;
                user.UserPhoto  = API.ImageToByte(picUserPhoto.Image);
                try
                {
                    API.Controllers.Staffs.Create(user);
                    API.Message("User Created Successfully !", MessageBoxIcon.Information);
                    API.ClearFields(this.Controls);
                }
                catch (Exception ex)
                {
                    API.Message(ex.Message, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                //
                API.Message(error, MessageBoxIcon.Warning);
            }
        }
        private void CreateAccount(object sender, RoutedEventArgs e)
        {
            Models.FCS_DBModel db = new Models.FCS_DBModel();
            string Role = UserRole.SelectedValue.ToString();

            string password = Password.Password.ToString();
            string verifiedPW = VerifyPassword.Password.ToString();
            string hashedPassword = PasswordHashing.GetHashString(password);

            int usernameVerify = (from uv in db.Staff
                                  where uv.StaffUserName == UserName
                                  select uv).Count();
            if (Role == "No Access")
            {
                if (FirstName == null || FirstName == "" || LastName == null || LastName == "" || StaffTitle == null || StaffTitle == "")
                {
                    MessageBox.Show("Please check the data entered.");
                }
                else
                {
                    Models.Staff account = new Models.Staff();
                    account.StaffFirstName = FirstName;
                    account.StaffLastName = LastName;
                    account.StaffTitle = StaffTitle;
                    account.StaffUserName = UserName;
                    account.StaffPassword = hashedPassword;
                    account.StaffDBRole = Role;
                    db.Staff.Add(account);
                    db.SaveChanges();
                    this.Close();
                }
            }
            else
            {
                if (password.Length < 5)
                {
                    MessageBox.Show("Please pick a longer password (Minimum length of 5)");
                }
                else if (password != verifiedPW)
                {
                    MessageBox.Show("Passwords do not match!");
                }
                else if (UserName == null || UserName == "" || FirstName == null || FirstName == ""
                    || LastName == null || LastName == "" || StaffTitle == null || StaffTitle == "")
                {
                    MessageBox.Show("Please check the data entered. A required field is missing.");
                }
                else if (UserName.Contains(" "))
                {
                    MessageBox.Show("User name cannot contain spaces");
                }
                else if(usernameVerify != 0)
                {
                    MessageBox.Show("That username selected is already taken");
                }
                else
                {
                    Models.Staff account = new Models.Staff();
                    account.StaffFirstName = FirstName;
                    account.StaffLastName = LastName;
                    account.StaffTitle = StaffTitle;
                    account.StaffUserName = UserName;
                    account.StaffPassword = hashedPassword;
                    account.StaffDBRole = Role;
                    db.Staff.Add(account);
                    db.SaveChanges();
                    this.Close();
                }
            }
        }
Ejemplo n.º 32
0
 public void Signin(Models.Staff staff, bool isPersistent)
 {
     FormsAuthentication.SetAuthCookie(staff.Id.ToString(), isPersistent);
 }