Exemplo n.º 1
0
 public void AddUserImage(UserImageRecord values)
 {
     context.UserImg.Add(values);
 }
Exemplo n.º 2
0
 public void DeleteUserImage(UserImageRecord value)
 {
     context.UserImg.Remove(value);
 }
Exemplo n.º 3
0
        public async Task <IActionResult> RegisterStaff(RegisterStaffModel model, List <IFormFile> UserImage)
        {
            if (ModelState.IsValid)
            {
                var polly = await userManager.FindByEmailAsync(model.Email);

                if (polly == null)
                {
                    IFormFile f = UserImage.FirstOrDefault();
                    if (f.Length > 0)
                    {
                        if (IsImage(f))
                        {
                            byte[] imageData = null;
                            using (var binary = new MemoryStream())
                            {
                                await f.CopyToAsync(binary);

                                imageData = binary.ToArray();
                            }
                            var user = new CleaningUser
                            {
                                Id          = Guid.NewGuid().ToString(),
                                Fullname    = model.Fullname,
                                Email       = model.Email,
                                PhoneNumber = model.PhoneNumber,
                                UserName    = model.Email,
                                Created     = DateTime.Now
                            };
                            var k = new UserImageRecord
                            {
                                Staff  = user,
                                Upload = imageData
                            };
                            var result = await userManager.CreateAsync(user, model.Password);

                            UserImageImp.AddUserImage(k);

                            if (result.Succeeded)
                            {
                                await userManager.AddToRoleAsync(user, model.UserRoles);

                                HttpContext.Session.SetString("Success", "Registration in Progress,check your email to complete the registration");
                                var token = await userManager.GenerateEmailConfirmationTokenAsync(user);

                                string confirmationEmail = Url.Action("ConfirmEmailAddress", "Local",
                                                                      new { token, email = user.Email }, Request.Scheme);
                                string confirm = "Please confirm your account by clicking this link: <a href=\""
                                                 + confirmationEmail + "\">link</a>";

                                EmailService.Send(user.Email, user.Fullname, "Confirmation message", confirm);

                                ModelState.Clear();

                                return(RedirectToAction("RegisterStaff"));
                            }
                        }
                        else
                        {
                            ViewBag.NotRightFormat = "you have not uploaded an image";
                        }
                    }
                    else
                    {
                        ViewBag.noImage = "you have not uploaded an image";
                    }
                }
                else
                {
                    ViewBag.Exist = "Registration in Progress,check your email to complete the registration";
                    string confirm = "you attempted to register an email address that already exist on the system if you would like to login:<a href= \"" + Url.Action("Login", "Account") + "\">click here</a>";
                    EmailService.Send(polly.Email, polly.Fullname, "Account Exist", confirm);
                }
            }
            ViewBag.role = GetUserRole();
            return(View());
        }