Esempio n. 1
0
        public ActionResult Create(UserViewModel userViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    string UniqFileName = DateTime.Now.ToString("yyyymmddMMss") + userViewModel.ImageFile.FileName;
                    User user = new User()
                    {
                        Address = userViewModel.Address,
                        BloodGroup = userViewModel.BloodGroup,
                        CitizenShipNumber = userViewModel.CitizenShipNumber,
                        //CreatedBy = userViewModel.CreatedBy,
                        //CreatedDate = userViewModel.CreatedDate,
                        DateOfBirth = userViewModel.DateOfBirth,
                        Email = userViewModel.Email,
                        ImageFile = UniqFileName,
                        //ModifiedBy = userViewModel.ModifiedBy,
                        //ModifiedDate = userViewModel.ModifiedDate,
                        Nationality = userViewModel.Nationality,
                        Password = userViewModel.Password,
                        PhoneNumber = userViewModel.PhoneNumber,
                        Religion = userViewModel.Religion,
                        Sex = userViewModel.Sex,
                        UserName = userViewModel.UserName,
                        FirstName = userViewModel.FirstName,
                        MiddleName = userViewModel.MiddleName,
                        LastName = userViewModel.LastName,
                        Semester = userViewModel.Semester,
                        Guardian1Name = userViewModel.Guardian1Name,
                        Guardian1PhoneNumber = userViewModel.Guardian1PhoneNumber,
                        Guardian2Name = userViewModel.Guardian2Name,
                        Guardian2PhoneNumber = userViewModel.Guardian2PhoneNumber,
                        //Sex = userViewModel.Sex,
                    };
                    string ImageFilePath = System.IO.Path.Combine(Server.MapPath("~/Uploads/UserImage"), UniqFileName);
                    userViewModel.ImageFile.SaveAs(ImageFilePath);
                    db.Users.Add(user);
                    db.SaveChanges();

                    IdentityManager im = new IdentityManager();
                    ApplicationUser userForLogin = new ApplicationUser() { UserName = user.UserName, };
                    im.CreateUser(userForLogin, user.Password);

                    return RedirectToAction("Index");
                }
                return View(userViewModel);
            }

            catch
            {
                return View();
            }
        }
Esempio n. 2
0
 public ActionResult Edit(int id, UserViewModel userViewModel)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             User user = new User()
             {
                 UserId = id,
                 Address = userViewModel.Address,
                 //BloodGroup = userViewModel.BloodGroup,
                 CitizenShipNumber = userViewModel.CitizenShipNumber,
                 //CreatedBy = userViewModel.CreatedBy,
                 //CreatedDate = userViewModel.CreatedDate,
                 DateOfBirth = userViewModel.DateOfBirth,
                 Email = userViewModel.Email,
                 ImageFile = userViewModel.ImageFile.ToString(),
                 //ModifiedBy = userViewModel.ModifiedBy,
                 //ModifiedDate = userViewModel.ModifiedDate,
                 Nationality = userViewModel.Nationality,
                 Password = userViewModel.Password,
                 PhoneNumber = userViewModel.PhoneNumber,
                 Religion = userViewModel.Religion,
                 //Sex = userViewModel.Sex,
                 UserName = userViewModel.UserName,
                 FirstName = userViewModel.FirstName,
                 MiddleName = userViewModel.MiddleName,
                 LastName = userViewModel.LastName,
             };
             db.Entry(user).State = EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(userViewModel);
     }
     catch
     {
         return View();
     }
 }