public async Task <ActionResult> RegisterCompany(RegisterCompanyViewModel model) { if (ModelState.IsValid) { //var appDbContext = HttpContext.GetOwinContext().Get<EMSDbContext>(); //using (var context = appDbContext.Database.BeginTransaction()) //{ // try // { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var company = new CompanyMD(); company.Name = model.Name; company.ImagePath = ""; company.Logo = ""; company.CreatedDate = DateTime.Now; company.Id = user.Id; company.CreatedById = 0; user.Company = company.Translate(); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); var res = _CompanyService.RegisterCompany(company); if (res.HasErrors) { await UserManager.DeleteAsync(user); } // For more information on how to enable account confirmation and password reset please visit http://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); //} //catch (Exception) //{ // context.Rollback(); //} } } return(View(model)); }
public CompanyMD RegisterCompany(CompanyMD mod) { try { var entity = mod.Translate(); _CompanyRepo.Insert(entity); _CompanyRepo.CommitAllChanges(); mod.AddSuccessMessage(string.Format(AppConstants.CRUD_ADD, "Company")); mod.Id = entity.Id; } catch (Exception ex) { mod.AddErrorMessage(string.Format(AppConstants.CRUD_ADD_ERROR, "Company")); } return(mod); }
public CompanyMD ModifyCompany(CompanyMD mod) { var entity = mod.Translate(); try { _CompanyRepo.Update(entity); _CompanyRepo.CommitAllChanges(); mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE, "Company")); } catch (Exception) { mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE_ERROR, "Company")); } return(mod); }