public ActionResult AddOrEdit(int id = 0) { if (id == 0) { return(View(new mvcEmplyeeModel())); } else { HttpResponseMessage response = GlobalHttp.WebApiClient.GetAsync("Employees/" + id.ToString()).Result; mvcEmplyeeModel employee = response.Content.ReadAsAsync <mvcEmplyeeModel>().Result; return(View(employee)); } }
public ActionResult AddOrEdit(mvcEmplyeeModel Employee) { if (Employee.EmpId == 0) { HttpResponseMessage response = GlobalHttp.WebApiClient.PostAsJsonAsync("Employees", Employee).Result; TempData["SuccessMessage"] = "Employee Record Added Successfully"; } else { HttpResponseMessage response = GlobalHttp.WebApiClient.PutAsJsonAsync("Employees/" + Employee.EmpId, Employee).Result; TempData["SuccessMessage"] = "Employee Record Updated Successfully"; } return(RedirectToAction("Index")); }
public async Task <ActionResult> EmployeeRegister(EmployeeRegisterViewModel model) { mvcEmplyeeModel employee = new mvcEmplyeeModel(); Console.WriteLine("I m here"); if (ModelState.IsValid) { int shopID = 3; var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; //Shop Detail IEnumerable <mvcShopModel> shops; HttpResponseMessage response = GlobalHttp.WebApiClient.GetAsync("Shops").Result; shops = response.Content.ReadAsAsync <IEnumerable <mvcShopModel> >().Result; foreach (var shop in shops) { if (shop.ShopName == model.ShopName) { shopID = shop.ShopId; } } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); //Employee Detail employee.EmpName = model.EmployeeName; employee.EmpEmail = model.Email; employee.EmpUsername = model.EmployeeName; employee.ShopId = shopID; HttpResponseMessage respons = GlobalHttp.WebApiClient.PostAsJsonAsync("Employees", employee).Result; // 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); MailMessage msg = new MailMessage(); msg.From = new MailAddress("*****@*****.**"); msg.To.Add(new MailAddress(model.Email)); msg.Subject = "Verify Your Email"; msg.Body = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"; SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", Convert.ToInt32(587)); System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "TijaratPOS000"); smtpClient.Credentials = credentials; smtpClient.EnableSsl = true; smtpClient.Send(msg); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); TempData["SuccessMessage"] = "Please Verify Your Email Address!!"; return(RedirectToAction("Login")); } AddErrors(result); } TempData["AlertMessage"] = "Something Went Wrong!! May be User Exist with Same Email Address."; // If we got this far, something failed, redisplay form return(View(model)); }