public ActionResult Create([Bind(Include = "CustomerId,SalesType,ReferenceNo")] SalesInvoiceViewModel salesInvoiceViewModel, int CustomerList, int BranchList, int?SalesTypeList) { if (ModelState.IsValid) { var exists = _salesInvoiceService.Get(t => t.ReferenceNo == salesInvoiceViewModel.ReferenceNo).FirstOrDefault(); if (exists != null) { return(View(salesInvoiceViewModel)); } MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); UserManager <MyIdentityUser> userManager = new UserManager <MyIdentityUser>(userStore); MyIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name); var salesInvoice = new SalesInvoice() { BranchId = BranchList, CustomerId = CustomerList, ReferenceNo = salesInvoiceViewModel.ReferenceNo, SalesType = SalesTypeList ?? 0, UserId = user.Id, DateSold = DateTime.Now, Status = "Draft" }; _salesInvoiceService.AddSalesInvoice(salesInvoice); return(RedirectToAction("Create", "SalesInvoices", new { id = salesInvoice.SalesInvoiceId })); } return(View(salesInvoiceViewModel)); }