Ejemplo n.º 1
0
        public JsonResult editAttendance(string id, string aDate, string presence)
        {
            int x = int.Parse(id);

            if (Request.IsAjaxRequest())
            {
                FastAndEasyEntities db = new FastAndEasyEntities();
                Attendence          a  = new Attendence();
                a      = db.Attendences.Find(x);
                a.Date = DateTime.Parse(aDate);
                if (presence == "-")
                {
                    a.Reasonable = "No";
                    db.Entry(a).Property(at => at.Reasonable).IsModified = true;
                }
                a.Present = presence;
                db.Entry(a).Property(at => at.Date).IsModified    = true;
                db.Entry(a).Property(at => at.Present).IsModified = true;
                db.SaveChanges();
                ModelState.Clear();
                return(new JsonResult {
                    Data = " ", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            return(new JsonResult {
                Data = "error", JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Ejemplo n.º 2
0
        public ActionResult EditPassword(string oldPass, string newPass, string newPassConfirm, Reception d)
        {
            FastAndEasyEntities _db = new FastAndEasyEntities();
            string receptionistName = HttpContext.User.Identity.Name;
            string pass             = _db.Receptions.Where(p => (p.Email.Equals(receptionistName)) || (p.UserName.Equals(receptionistName))).FirstOrDefault().Password;

            ViewBag.Pass = pass;

            if (Crypto.VerifyHashedPassword(pass, oldPass))
            {
                if ((newPass == newPassConfirm))
                {
                    db.Receptions.Attach(d);
                    d.Password = Crypto.HashPassword(newPass);
                    db.Entry(d).Property(p => p.Password).IsModified = true;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = d.Id }));
                }
                else
                {
                    ViewBag.Error = "Passwords Do not Match";
                }
            }
            else
            {
                ViewBag.Error = "Wrong Current Password";
            }

            return(View());
        }
Ejemplo n.º 3
0
        public JsonResult studentPay(string sId, string groupId, string amount)
        {
            int    sid   = int.Parse(sId);
            int    grpID = int.Parse(groupId);
            double sum   = float.Parse(amount);

            using (FastAndEasyEntities db = new FastAndEasyEntities())
            {
                int?   levelId = db.Groups.Where(g => g.Id == grpID).FirstOrDefault().Level;
                double?cost    = db.Levels.Where(l => l.Id == levelId).FirstOrDefault().Price;
                var    x       = sum / cost;
                for (int i = 1; i <= x; i++)
                {
                    Attendence a = new Attendence();
                    a.Student = sid;
                    db.Attendences.Add(a);
                    db.SaveChanges();
                    ModelState.Clear();
                }



                return(Json("success", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 4
0
        public JsonResult deleteStudent(string id, string LastName, string FirstName)
        {
            int x = int.Parse(id);

            using (FastAndEasyEntities db = new FastAndEasyEntities())
            {
                Student d = new Student();
                d = db.Students.Find(x);
                db.Entry(d).State = EntityState.Deleted;
                db.SaveChanges();
                ModelState.Clear();
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
        public JsonResult addNewReceptionist(string LastName, string FirstName, string UserName, string pass, string Phone, string Email)
        {
            FastAndEasyEntities db      = new FastAndEasyEntities();
            Reception           manager = new Reception();

            manager.UserName  = UserName;
            manager.Password  = Crypto.HashPassword(pass);
            manager.LastName  = LastName;
            manager.FirstName = FirstName;
            manager.Phone     = Phone;
            manager.Email     = Email;
            manager.RoleId    = 3;
            db.Receptions.Add(manager);
            db.SaveChanges();
            ModelState.Clear();
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public JsonResult editStudent(string id, string LastName, string FirstName)
        {
            int x = int.Parse(id);

            using (FastAndEasyEntities db = new FastAndEasyEntities())
            {
                Student d = new Student();
                d = db.Students.Find(x);
                db.Students.Attach(d);
                d.LastName  = LastName;
                d.FirstName = FirstName;
                db.Entry(d).Property(p => p.LastName).IsModified  = true;
                db.Entry(d).Property(p => p.FirstName).IsModified = true;
                db.SaveChanges();
                ModelState.Clear();
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 7
0
        public JsonResult addStudent(string id, string LastName, string FirstName)
        {
            int x = int.Parse(id);

            using (FastAndEasyEntities db = new FastAndEasyEntities())
            {
                Student d = new Student();
                d.UserName  = LastName + FirstName;
                d.Password  = Crypto.HashPassword("1111");
                d.LastName  = LastName;
                d.FirstName = FirstName;
                d.RoleId    = 5;
                d.Group     = x;
                db.Students.Add(d);
                db.SaveChanges();
                ModelState.Clear();
                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 8
0
        public JsonResult updateTeacher(string id, string LastName, string FirstName, string UserName, string pass, string Phone, string Email)
        {
            int Id = int.Parse(id);
            FastAndEasyEntities db      = new FastAndEasyEntities();
            Teacher             manager = new Teacher();

            manager                 = db.Teachers.Find(Id);
            manager.UserName        = UserName;
            manager.Password        = Crypto.HashPassword(pass);
            manager.LastName        = LastName;
            manager.FirstName       = FirstName;
            manager.Phone           = Phone;
            manager.Email           = Email;
            manager.RoleId          = 4;
            db.Entry(manager).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            ModelState.Clear();
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        public ActionResult Edit(HttpPostedFileBase ImageFile, Reception d, string pass, string passConf)
        {
            if (ModelState.IsValid)
            {
                if (pass == passConf)
                {
                    var db = new FastAndEasyEntities();
                    db.Receptions.Attach(d);
                    if (ImageFile != null)
                    {
                        string fileName      = Path.GetFileNameWithoutExtension(ImageFile.FileName);
                        string fileExtension = Path.GetExtension(ImageFile.FileName);
                        fileName    = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension;
                        d.ImagePath = "/img/photos/reception/" + fileName;
                        fileName    = Path.Combine(Server.MapPath("/img/photos/reception/"), fileName);
                        ImageFile.SaveAs(fileName);
                    }


                    db.Entry(d).Property(p => p.LastName).IsModified  = true;
                    db.Entry(d).Property(p => p.FirstName).IsModified = true;
                    db.Entry(d).Property(p => p.DoB).IsModified       = true;
                    db.Entry(d).Property(p => p.Address).IsModified   = true;
                    db.Entry(d).Property(p => p.Phone).IsModified     = true;
                    db.Entry(d).Property(p => p.Email).IsModified     = true;
                    db.Entry(d).Property(p => p.ImagePath).IsModified = true;
                    db.SaveChanges();

                    return(RedirectToAction("Index", new { id = d.Id }));
                }
                else
                {
                    ViewBag.Pass = "******";
                    return(View());
                }
            }
            return(View());
        }
        public MembershipUser CreateUser(string email, string password)
        {
            MembershipUser membershipUser = GetUser(email, false);

            if (membershipUser == null)
            {
                try
                {
                    using (FastAndEasyEntities _db = new FastAndEasyEntities())
                    {
                        Admin admin = new Admin();
                        admin.Email    = email;
                        admin.Password = Crypto.HashPassword(password);
                        //admin.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(1) != null)
                        {
                            admin.RoleId = 1;
                        }



                        _db.Admins.Add(admin);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return(membershipUser);

#pragma warning disable CS0162 // Unreachable code detected
                        Manager director = new Manager();
#pragma warning restore CS0162 // Unreachable code detected
                        director.Email    = email;
                        director.Password = Crypto.HashPassword(password);
                        //admin.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(2) != null)
                        {
                            director.RoleId = 2;
                        }

                        _db.Managers.Add(director);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return(membershipUser);



#pragma warning disable CS0162 // Unreachable code detected
                        Reception parent = new Reception();
#pragma warning restore CS0162 // Unreachable code detected
                        parent.Email    = email;
                        parent.Password = Crypto.HashPassword(password);

                        if (_db.Roles.Find(3) != null)
                        {
                            parent.RoleId = 3;
                        }

                        _db.Receptions.Add(parent);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return(membershipUser);

#pragma warning disable CS0162 // Unreachable code detected
                        Teacher teacher = new Teacher();
#pragma warning restore CS0162 // Unreachable code detected
                        teacher.Email    = email;
                        teacher.Password = Crypto.HashPassword(password);
                        //admin.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(4) != null)
                        {
                            teacher.RoleId = 4;
                        }

                        _db.Teachers.Add(teacher);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return(membershipUser);

                        Student pupil = new Student();
                        pupil.Email    = email;
                        pupil.Password = Crypto.HashPassword(password);
                        //admin.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(5) != null)
                        {
                            pupil.RoleId = 5;
                        }

                        _db.Students.Add(pupil);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return(membershipUser);
                    }
                }
                catch
                {
                    return(null);
                }
            }
            return(null);
        }
Ejemplo n.º 11
0
        public JsonResult editManager(string LastName, string FirstName, string UserName, string pass, string Phone, string Email)
        {
            string UserNameError   = " ";
            string LNameError      = " ";
            string FNameError      = " ";
            string PassError       = " ";
            string PhoneError      = " ";
            string EmailError      = " ";
            var    rName           = new Regex(@"^[A-Z][a-z]+$");
            var    hasNumber       = new Regex(@"[0-9]+");
            var    hasChar         = new Regex(@"[A-Za-z]+");
            var    hasMiniMaxChars = new Regex(@".{6, }");
            var    rLogin          = new Regex(@"^[A-Za-z\d]+$");
            var    rPhone          = new Regex(@"^\+9989[0-9]{8}$");
            var    rEmail          = new Regex(@"^.+$");
            FastAndEasyEntities db = new FastAndEasyEntities();

            if (!rName.IsMatch(LastName))
            {
                LNameError = "Lastname should only contain letters with a capital letter at the beginning and not be empty! Example: 'Khamzaev'!";
            }
            if (!rName.IsMatch(FirstName))
            {
                FNameError = "Firstname should only contain letters with a capital letter at the beginning and not be empty! Example: 'Asilbek'!";
            }
            if (!rLogin.IsMatch(UserName))
            {
                UserNameError = "Username should only contain letters and numbers and not be empty! Example: 'AceTheKing', 'ACETHEKING', 'acetheking' or 'acetheking7776'!";
            }
            //if (ifAExists(UserName) != null)
            //{
            //    UserNameError = "The user already exists!";
            //}
            if (ifMExists(UserName) != null)
            {
                UserNameError = "The user already exists!";
            }
            if (ifRExists(UserName) != null)
            {
                UserNameError = "The user already exists!";
            }
            if (ifTExists(UserName) != null)
            {
                UserNameError = "The user already exists!";
            }
            if (ifSExists(UserName) != null)
            {
                UserNameError = "The user already exists!";
            }
            if (!hasNumber.IsMatch(pass))
            {
                PassError = "The password should contain at least one number!";
            }
            else if (!hasChar.IsMatch(pass))
            {
                PassError = "The password should contain at least one letter!";
            }
            else if (!hasMiniMaxChars.IsMatch(pass))
            {
                PassError = "The password should be at least six characters long!";
            }
            else
            {
                PassError = " ";
            }
            if (!rPhone.IsMatch(Phone))
            {
                PhoneError = "Enter full UZB phone number! Example: '+998945677776'";
            }
            if (!string.IsNullOrEmpty(Email) && !string.IsNullOrWhiteSpace(Email))
            {
                if (!IsValidEmail(Email))
                {
                    EmailError = "Invalid email address!";
                }
            }
            if (UserNameError == " " && PassError == " " && LNameError == " " && FNameError == " " &&
                PhoneError == " " && EmailError == " ")
            {
                Manager manager = new Manager();
                manager                 = db.Managers.Find(1);
                manager.UserName        = UserName;
                manager.Password        = Crypto.HashPassword(pass);
                manager.LastName        = LastName;
                manager.FirstName       = FirstName;
                manager.Phone           = Phone;
                manager.Email           = Email;
                manager.RoleId          = 2;
                db.Entry(manager).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                ModelState.Clear();
                var result = "success";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var result = new { LNameError, FNameError, UserNameError, PassError, PhoneError, EmailError };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }