Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task <ActionResult> Add(VmDonorAdd model)
        {
            if (ModelState.IsValid)
            {
                #region Image Upload
                var uri = Request.Url.Host;
                System.IO.Directory.CreateDirectory(Server.MapPath("~/Images/ProfilePic/" + uri));
                string path = "";
                if (model.ProPic != null)
                {
                    string pic          = System.IO.Path.GetFileName(model.ProPic.FileName);
                    string physicalPath =
                        System.IO.Path.Combine(Server.MapPath("~/Images/ProfilePic/" + uri), pic);
                    path = "/Images/ProfilePic/" + uri + "/" + pic;
                    model.ProPic.SaveAs(physicalPath);
                    model.ImageUrl = path;
                }
                #endregion
                model.DOB         = DateTimeHelperService.ConvertBDDateStringToDateTimeObject(model.DOB);
                model.LastDonated = !string.IsNullOrEmpty(model.LastDonated) ?DateTimeHelperService.ConvertBDDateStringToDateTimeObject(model.LastDonated):null;
                var donorService  = new DonorService(db);
                int donorHeaderId = 0;
                donorService.Add(model, out donorHeaderId);
                if (model.BloodDonorHeaderId == 0 && model.Password == model.ConfirmPassword)
                {
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email, UserType = (int)UserType.Donor, ReferrenceId = donorHeaderId, CreationDate = DateTime.Now, LastUpdateDate = DateTime.Now
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        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"));
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }