public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase upload) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, IsAcceptedOnCondition = model.IsAcceptedOnCondition, HourlyRate = model.HourlyRate, O_T_H_Rate = model.O_T_H_Rate, JopTitle = model.JopTitle, MyFiles = new List <MyUserFile>() }; //Guid is used as a file name on the basis that it can pretty much guarantee uniqueness if (upload != null && upload.ContentLength > 0) { var photo = new MyUserFile() { FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(upload.FileName), MyFileType = MyFileType.Photo }; string physicalPath = Server.MapPath("~/images/" + photo.FileName); // save image in folder upload.SaveAs(physicalPath); user.MyFiles.Add(photo); } 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("ListUser", "User")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create(RegisterViewModel model, HttpPostedFileBase upload) { try { // TODO: Add insert logic here var newUser = new ApplicationUser { UserName = model.UserName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, IsAcceptedOnCondition = model.IsAcceptedOnCondition, JopTitle = model.JopTitle, O_T_H_Rate = model.O_T_H_Rate, HourlyRate = model.HourlyRate, MyFiles = new List <MyUserFile>() }; //Guid is used as a file name on the basis that it can pretty much guarantee uniqueness if (upload != null && upload.ContentLength > 0) { var photo = new MyUserFile() { FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(upload.FileName), MyFileType = MyFileType.Photo }; string physicalPath = Server.MapPath("~/images/" + photo.FileName); // save image in folder upload.SaveAs(physicalPath); newUser.MyFiles.Add(photo); } //i dont user Manager here, because no need to write here.. _unitOfWork.UserRepositry.AddUser(newUser, model.Password); _unitOfWork.Complete(); return(RedirectToAction("ListUser")); } catch { return(View()); } }
public ActionResult SettingEmployee(ApplicationUser applicationUser, HttpPostedFileBase upload) { try { var currentUser = _unitOfWork.UserRepositry.GetUserWithProjectsAndTasksAndRolesAndFilesAndFinanicalWithFilesWithPayments( applicationUser.Id); //update the new data currentUser.Email = applicationUser.Email; currentUser.FirstName = applicationUser.FirstName; currentUser.LastName = applicationUser.LastName; currentUser.JopTitle = applicationUser.JopTitle; currentUser.HourlyRate = applicationUser.HourlyRate; //update image// create new one and show the last one in the view //Guid is used as a file name on the basis that it can pretty much guarantee uniqueness if (upload != null && upload.ContentLength > 0) { var photo = new MyUserFile() { FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(upload.FileName), MyFileType = MyFileType.Photo }; string physicalPath = Server.MapPath("~/images/" + photo.FileName); // save image in folder upload.SaveAs(physicalPath); currentUser.MyFiles = new List <MyUserFile>(); currentUser.MyFiles.Add(photo); } _unitOfWork.UserRepositry.Add(currentUser); //this is for add or update _unitOfWork.Complete(); return(RedirectToAction("SettingEmployee")); } catch (Exception exception) { return(View()); } }