public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };


                if (ImageUploadValidator.IsWebFriendlyImage(model.AvatarUrl))
                {
                    var filename = Path.GetFileName(model.AvatarUrl.FileName);
                    model.AvatarUrl.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename));
                    user.AvatarUrl = "/Uploads/" + filename;
                }

                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>");


                    UserManager.AddToRole(user.Id, "None");
                    TempData["Confirm"] = "Confirm";
                    return(RedirectToAction("Login", "Account"));
                }
                TempData["ErrorMsg"] = "Error";
                return(RedirectToAction("Login"));
            }

            // If we got this far, something failed, redisplay form
            TempData["ErrorMsg"] = "Error";
            return(RedirectToAction("Login"));
        }
 public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment model, string attachmentTitle, string attachmentDescription, HttpPostedFileBase fileAttachment)
 {
     if (ModelState.IsValid)
     {
         model.Title       = attachmentTitle;
         model.Description = attachmentDescription;
         model.Created     = DateTime.Now;
         model.UserId      = User.Identity.GetUserId();
         if (ImageUploadValidator.IsAttachmentValid(fileAttachment))
         {
             var filename = Path.GetFileName(fileAttachment.FileName);
             fileAttachment.SaveAs(Path.Combine(Server.MapPath("~/TixAttachments/"), filename));
             model.FileUrl = "/TixAttachments/" + filename;
         }
         db.TicketAttachments.Add(model);
         db.SaveChanges();
         return(RedirectToAction("Index", "Tickets"));
     }
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", model.TicketId);
     ViewBag.UserId   = new SelectList(db.Tickets, "Id", "FirstName", model.TicketId);
     return(View(model));
 }