Beispiel #1
0
        public async Task SaveAsync(User entity)
        {
            try
            {
                if (entity == null)
                {
                    return;
                }

                using (var timeLineContext = _contextFactory.GetTimeLineContext())
                {
                    var entityModel = await timeLineContext
                                      .Users
                                      .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id));

                    if (entityModel == null)
                    {
                        entityModel = new DA.User();
                        MapForUpdateentity(entity, entityModel);
                        await timeLineContext.Users.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateentity(entity, entityModel);
                    }


                    timeLineContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public async Task <int> SaveAsync(BL.User entity)
        {
            try
            {
                if (entity == null)
                {
                    return(0);
                }

                using (var context = _contextFactory.GetProductContext())
                {
                    var entityModel = await context
                                      .Users
                                      .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id));

                    if (entityModel == null)
                    {
                        entityModel = new DA.User();
                        MapForUpdateEntity(entity, entityModel);
                        await context.Users.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateEntity(entity, entityModel);
                    }

                    context.SaveChanges();
                    return(entityModel.Id);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
 private void MapForUpdateEntity(BL.User entity, DA.User daEntity)
 {
     daEntity.Id       = entity.Id;
     daEntity.Name     = entity.Name;
     daEntity.Email    = entity.Email;
     daEntity.Password = entity.Password;
     daEntity.RoleId   = entity.RoleId;
 }
Beispiel #4
0
        public ActionResult Registration(RegistrationView registrationView)
        {
            bool   statusRegistration  = false;
            string messageRegistration = string.Empty;

            if (ModelState.IsValid)
            {
                // Email Verification
                string userName = Membership.GetUserNameByEmail(registrationView.Email);
                if (!string.IsNullOrEmpty(userName))
                {
                    ModelState.AddModelError("Warning Email", "Sorry: Email already Exists");
                    return(View(registrationView));
                }

                //Save User Data
                using (DataContext dbContext = new DataContext())
                {
                    var user = new DataAccess.Models.User()
                    {
                        Username  = registrationView.Username,
                        FirstName = registrationView.FirstName,
                        LastName  = registrationView.LastName,
                        Email     = registrationView.Email,
                        Password  = registrationView.Password,
                    };

                    dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                }

                //Verification Email
                VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString());
                messageRegistration = "Your account has been created successfully. ^_^";
                statusRegistration  = true;
            }
            else
            {
                messageRegistration = "Something Wrong!";
            }
            ViewBag.Message = messageRegistration;
            ViewBag.Status  = statusRegistration;

            return(View(registrationView));
        }
Beispiel #5
0
 public ActionResult Edit(UserViewModel editViewModel)
 {
     if (userService.PreValidate())
     {
         User userInput = new DataAccess.Models.User();
         userInput.Id       = editViewModel.Id;
         userInput.IsAdmin  = editViewModel.IsAdmin;
         userInput.Name     = editViewModel.Name;
         userInput.Phone    = editViewModel.Phone;
         userInput.Email    = editViewModel.Email;
         userInput.Password = editViewModel.Password;
         if (userService.Save(userInput))
         {
             TempData["Message"] = "Edit made successfully!";
         }
         else
         {
             TempData["ErrorMessage"] = "Ooops something went wrong";
         }
         return(RedirectToAction("Index", "Home"));
     }
     return(View(editViewModel));
 }
Beispiel #6
0
        public ActionResult Register(RegisterUserViewModel registerViewModel)
        {
            User userInput = new DataAccess.Models.User();

            userInput.Name     = registerViewModel.Name;
            userInput.Password = registerViewModel.Password;
            userInput.IsAdmin  = false;
            userInput.Email    = registerViewModel.Email;
            userInput.Phone    = registerViewModel.Phone;
            if (!userService.ValidateUser(userInput))
            {
                return(View(registerViewModel));
            }

            if (userService.Save(userInput))
            {
                TempData["Message"] = "Registered successfully!";
            }
            else
            {
                TempData["ErrorMessage"] = "Ooops something went wrong";
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task AddCustomer_Database_TestAsync()
        {
            using var connection = new SqliteConnection("Data Source=:memory:");
            connection.Open();
            var options = new DbContextOptionsBuilder <mmpproject2Context>().UseSqlite(connection).Options;

            testUser = new Domain.Models.User("Grace", "Libardos", "*****@*****.**", "gl001", null);


            using (var context = new mmpproject2Context(options))
            {
                context.Database.EnsureCreated();
                var repo = new UserRepository(options);

                await repo.AddAsync(testUser);
            }

            using var context2 = new mmpproject2Context(options);
            DataAccess.Models.User userReal = context2.Users
                                              .Single(l => l.FirstName == "Grace");

            Assert.Equal(testUser.FirstName, userReal.FirstName);
            Assert.Equal(testUser.Email, userReal.Email);
        }
Beispiel #8
0
 private void MapForUpdateentity(User entity, DA.User daEntity)
 {
     daEntity.Id = entity.Id;
 }