Esempio n. 1
0
        public IActionResult SaveStudent(StudentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("StudentRegistration", ListsInput(model)));
            }

            var contact = new ContactInfo()
            {
                Email   = model.Email,
                Phone   = model.PhoneNummber,
                Address = model.Address
            };

            db.Contact.Add(contact);
            db.SaveChanges();

            var profileInfo = new ProfileInfo()
            {
                Username     = model.Username,
                PasswordSalt = PasswordHashAndSalt.GenerateSalt()
            };

            profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, model.Password);
            db.ProfileInfo.Add(profileInfo);
            db.SaveChanges();

            var newStudent = new Student()
            {
                FName         = model.FName,
                LName         = model.LName,
                DateOfBirth   = model.DateOfBirth,
                DateAdded     = DateTime.Today,
                ContactId     = contact.Id,
                CityId        = model.CityId,
                StudentTypeId = model.StudentTypeId,
                StatusId      = 1,
                GenderId      = model.GenderId,
                ProfileInfoId = profileInfo.Id
            };

            db.Student.Add(newStudent);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public IActionResult UpdateStudent(StudentViewModel model)
        {
            //Treba validacija za Email i telefon, za addrtesu ne treba jer neki useri mogu da dijele adresu


            var editedStudent = db.Student.FirstOrDefault(x => x.Id == model.StudentId);
            var contactInfo   = db.Contact.FirstOrDefault(x => x.Id == editedStudent.ContactId);
            var profileInfo   = db.ProfileInfo.FirstOrDefault(x => x.Id == editedStudent.ProfileInfoId);

            contactInfo.Email   = model.Email;
            contactInfo.Phone   = model.PhoneNummber;
            contactInfo.Address = model.Address;


            db.Contact.Update(contactInfo);
            db.SaveChanges();

            profileInfo.Username = model.Username;
            if (!String.IsNullOrEmpty(model.Password))
            {
                profileInfo.PasswordSalt = PasswordHashAndSalt.GenerateSalt();
                profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, model.Password);
            }

            db.Update(profileInfo);
            db.SaveChanges();

            editedStudent.FName          = model.FName;       //readonly
            editedStudent.LName          = model.LName;       //readonly
            editedStudent.DateOfBirth    = model.DateOfBirth; //readonly
            editedStudent.DateAdded      = model.DateAdded;   //readonly
            editedStudent.ContactId      = contactInfo.Id;
            editedStudent.ProfileInfoId  = profileInfo.Id;
            editedStudent.CityId         = model.CityId;
            editedStudent.StudentTypeId  = model.StudentTypeId;
            editedStudent.ProfilePicture = model.ProfilePicture;//ako su isti biti ko vec nemjenjaj nista ako nisu onda mjenjaj treba dodat isto treba kompresovat sliku



            db.Update(editedStudent);
            db.SaveChanges();

            //Redirekcija se treba stavit
            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult UpdatedAdministrator(AdministratorVM obj)
        {
            var contactInfo = new ContactInfo()
            {
                Address = obj.Address,
                Email   = obj.Email,
                Phone   = obj.Phone
            };

            db.Contact.Update(contactInfo);
            db.SaveChanges();

            var profileInfo = new ProfileInfo()
            {
                Username = obj.Username,
            };

            if (!String.IsNullOrEmpty(obj.Password))
            {
                profileInfo.PasswordSalt = PasswordHashAndSalt.GenerateSalt();
                profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, obj.Password);
            }

            db.ProfileInfo.Update(profileInfo);
            db.SaveChanges();


            var editedAdministrator = new Administrator()
            {
                FName = obj.FirstName,
                LName = obj.LastName,
                AdministrastorRoleId = obj.AdministrastorRoleId,
                CityId        = obj.CityId,
                ProfileInfoId = profileInfo.Id,
                ContactInfoId = contactInfo.Id
            };

            db.Administrator.Update(editedAdministrator);
            db.SaveChanges();


            return(RedirectToAction());
        }
        public IActionResult SaveAdministrator(AdministratorVM obj)
        {
            var contactInfo = new ContactInfo()
            {
                Address = obj.Address,
                Email   = obj.Email,
                Phone   = obj.Phone
            };

            db.Contact.Add(contactInfo);
            db.SaveChanges();

            var profileInfo = new ProfileInfo()
            {
                Username     = obj.Username,
                PasswordSalt = PasswordHashAndSalt.GenerateSalt()
            };

            profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, obj.Password);
            db.ProfileInfo.Add(profileInfo);
            db.SaveChanges();


            var newAdministrator = new Administrator()
            {
                FName = obj.FirstName,
                LName = obj.LastName,
                AdministrastorRoleId = obj.AdministrastorRoleId,
                CityId        = obj.CityId,
                DateAdded     = DateTime.Now.ToUniversalTime(),
                ProfileInfoId = profileInfo.Id,
                ContactInfoId = contactInfo.Id
            };

            db.Administrator.Add(newAdministrator);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public IActionResult SaveTeacherRegistration(TeacherRegistrationVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View("TeacherRegistration", TeacherInput(model)));
            }

            var contact = new ContactInfo()
            {
                Email   = model.Email,
                Phone   = model.PhoneNummber,
                Address = model.Address
            };

            db.Contact.Add(contact);
            db.SaveChanges();

            var profileInfo = new ProfileInfo()
            {
                Username     = model.Username,
                PasswordSalt = PasswordHashAndSalt.GenerateSalt()
            };

            profileInfo.PasswordHash = PasswordHashAndSalt.GenerateHash(profileInfo.PasswordSalt, model.Password);

            db.ProfileInfo.Add(profileInfo);
            db.SaveChanges();

            var newTutor = new TutorRegistrationForm()
            {
                FName         = model.FName,
                LName         = model.LName,
                ProfileInfoId = profileInfo.Id,
                DateOfBirth   = model.DateOfBirth,
                CollageName   = model.CollageName,
                Price         = model.Price,
                TitleId       = model.TitleId,
                SubjectId     = model.SubjectId,
                ContactInfoId = contact.Id,
                CityId        = model.CityId,
                GenderId      = model.GenderId,
                IsRead        = false
            };



            if (model.ProfilePicture != null)
            {
                var fileExst     = Path.GetExtension(model.ProfilePicture.FileName);
                var newFileName  = Convert.ToString(Guid.NewGuid()) + fileExst;
                var fileName     = Path.Combine(hostingEnvironment.WebRootPath, "Profilepictures") + $@"\{newFileName}";
                var databaseName = "/Profilepictures/" + newFileName;
                model.ProfilePicture.CopyTo(new FileStream(fileName, FileMode.Create));
                newTutor.ProfilePicture = databaseName;
            }

            db.TutorRegistrationForm.Add(newTutor);
            db.SaveChanges();

            foreach (var item in model.typeOfStudents)
            {
                if (item.Checked)
                {
                    var PerferedType = new ListOfStudents()
                    {
                        TutorRegistrationFormId = newTutor.Id,
                        StudentTypeId           = item.StudentTypeId
                    };

                    db.ListOfStudents.Add(PerferedType);
                    db.SaveChanges();
                }
            }

            foreach (var item in model.Proof)
            {
                var fileExst    = Path.GetExtension(item.FileName);
                var newFileName = Convert.ToString(Guid.NewGuid()) + fileExst;
                var fileName    = Path.Combine(hostingEnvironment.WebRootPath, "ProofPictures") + $@"\{newFileName}";
                item.CopyTo(new FileStream(fileName, FileMode.Create));
                var databaseName = "/ProofPictures/" + newFileName;

                var proofPicture = new Proof()
                {
                    TutorRegistrationFormId = newTutor.Id,
                    PictureName             = databaseName
                };

                db.Proof.Add(proofPicture);
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }