public async Task <ActionResult> Login(LoginViewModel model, string returnUrl, FormCollection formcollection) { if (ModelState.IsValid) { var customer = new Customer(); var adminUser = new AdminUser(); if (formcollection["userTypeGrp"].Equals("1")) { customer = await client.AuthenticateCustomer(new Customer() { Email = model.Email, Password = model.Password }); } else { adminUser = await client.AuthenticateAdmin(new AdminUser() { Email = model.Email, Password = model.Password }); } if (customer != null && !string.IsNullOrEmpty(customer.Id)) { CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.CustomerID = customer.Id; serializeModel.FirstName = customer.Name; serializeModel.Email = customer.Email; serializeModel.UserTyepId = Convert.ToInt16(UserTypes.Customer); Response.Cookies.Add(Utility.Utility.EncryptAndSet(serializeModel)); if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect("../" + returnUrl)); } else { return(RedirectToAction("ConsumptionLog", "CustomerAccount")); } } if (adminUser != null && adminUser.Id > 0) { CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.CustomerID = adminUser.Id.ToString(); serializeModel.FirstName = "admin"; serializeModel.Email = adminUser.Email; serializeModel.UserTyepId = Convert.ToInt16(UserTypes.Admin); Response.Cookies.Add(Utility.Utility.EncryptAndSet(serializeModel)); if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect("../" + returnUrl)); } else { return(RedirectToAction("ManageCustomer", "AdminAccount")); } } ModelState.AddModelError("", "Incorrect username and/or password"); } return(View(model)); }