Esempio n. 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    User efUser = new User();
                    efUser.Address      = model.Address;
                    efUser.DOB          = model.DOB;
                    efUser.EmailAddress = model.Email;
                    efUser.FirstName    = model.FirstName;
                    efUser.LastName     = model.LastName;
                    efUser.PhoneNumber  = model.PhoneNumber;

                    var newAspUser = UserManager.FindByEmail(model.Email);
                    efUser.User_ID = newAspUser.Id;

                    using (var db = new EbayforCarsEntities())
                    {
                        db.Users.Add(efUser);
                        db.SaveChanges();
                    }
                    EmailUtility.sendMail(model.Email, "Welcome to Bid Up - Antique(s) Where You New Hot Rod Awaits! Happy Bidding");



                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public static Image Uploadimages(EbayforCarsEntities DB, HttpPostedFileBase file)
        {
            if (file == null)
            {
                return(null);
            }
            if (!file.ContentType.StartsWith("image/"))
            {
                return(null);
            }
            Image Pics = new Image();

            Pics.ContentType = file.ContentType;
            int extpos = file.FileName.LastIndexOf('.');

            Pics.Extension = file.FileName.Substring(extpos);
            Pics.Content   = new byte[file.ContentLength];
            file.InputStream.Read(Pics.Content, 0, file.ContentLength);
            var result = DB.Images.Add(Pics);

            DB.SaveChanges();
            return(result);
        }