Exemple #1
0
        public ViewResult Register(RegisterModel Rm, HttpPostedFileBase ProfilePicture)
        {
            List <string> matchContentType = new List <string>()
            {
                "image/jpeg", "image/png", "image/gif"
            };

            if (!matchContentType.Contains(ProfilePicture.ContentType) || ProfilePicture.ContentLength > 80000)
            {
                ViewBag.ErrorMessage = "You can upload a file with the following exctentions(png, jpg, gif)";
                return(View());
            }
            if (!ModelState.IsValid)
            {
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        ViewBag.ErrorMessage += error.ErrorMessage + "<br>";
                    }
                }
            }
            else
            {
                // insert the new reader
                ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
                Reader           R  = Rr.Insert(MapToDbModels.RegisterToReader(Rm));
                if (R != null)
                {
                    //saving the picture
                    string[] splitFileName  = ProfilePicture.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                    string   ext            = splitFileName[splitFileName.Length - 1];
                    string   newFileName    = R.Id + "." + ext;
                    string   folderpath     = Server.MapPath("~/Photos/");
                    string   FileNameToSave = folderpath + "/" + newFileName;

                    try
                    {
                        ProfilePicture.SaveAs(FileNameToSave);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMessage = "The image couldn't be saved";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Error during Insertion";
                }
            }
            return(View("Login"));
        }
        public ActionResult Create(Reader reader)
        {
            if (!ModelState.IsValid)
            {
                return(View(reader));
            }
            ReaderRepository rep = new ReaderRepository(AppConfig.ConnectionString);

            if (Regex.IsMatch(reader.FirstName, @"^[a-zA-Z]+$") == true && Regex.IsMatch(reader.FamilyName, @"^[a-zA-Z]+$") == true)
            {
                rep.Insert(reader);
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.error = "Wrong Name !!!";
                return(View());
            }
        }
Exemple #3
0
        public ActionResult Create(ReaderCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Reader readers = new Reader();

            readers.firstName  = model.firstName;
            readers.lastName   = model.lastName;
            readers.readerCard = model.readerCard;
            readers.expireDate = model.expireDate;

            var repository = new ReaderRepository();

            repository.Insert(readers);

            return(RedirectToAction("Index"));
        }
        private void InitializeUsers()
        {
            List <Reader> users = new List <Reader>
            {
                new Reader()
                {
                    Email = "*****@*****.**", Password = "******", Gender = "man", Phone = "", FirstName = "user", SecondName = "user", Date = new DateTime(2000, 8, 28)
                },
                new Reader()
                {
                    Email = "*****@*****.**", Password = "******", Gender = "female", Phone = "0930000000", FirstName = "admin", SecondName = "admin", Date = new DateTime(2000, 01, 06)
                }

                // new Author() { FirstName = "Лев", SecondName = "Толстой", DateBorn = new DateTime(1828, 8, 28), DateDied = new DateTime(1910, 11, 7), Nationality = "Россия" }

                //new Reader{Login = "******", Password = "******", Admin = false},
                //new Reader { Login = "******", Password = "******", Admin = true }
            };

            foreach (Reader user in users)
            {
                readerRepository.Insert(user);
            }
        }