protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); RoleManager <MyIdentityRole> roleManager = new RoleManager <MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole newRole = new MyIdentityRole("Administrator", "Администратор обладает полными правами в системе"); roleManager.Create(newRole); } if (!roleManager.RoleExists("Operator")) { MyIdentityRole newRole = new MyIdentityRole("Operator", "Операторы могут только добавлять и изменять данные в системе"); roleManager.Create(newRole); } if (!roleManager.RoleExists("Student")) { MyIdentityRole newRole = new MyIdentityRole("Student", "Студенты могут просматривать данные о нарушениях"); roleManager.Create(newRole); } if (!roleManager.RoleExists("Boss")) { MyIdentityRole newRole = new MyIdentityRole("Boss", "Директор млжет просматривать всё!"); roleManager.Create(newRole); } }
public AuthenticationController() { var context = new MyIdentityDbContext(); var store = new UserStore <IdentityUser>(context); userManager = new UserManager <IdentityUser>(store); }
public ActionResult Index() { 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); NorthWindEntities northwindDb = new NorthWindEntities(); List<Customer> customers = null; if (userManager.IsInRole(user.Id, "Administrator")) { customers = northwindDb.Customers.ToList(); } if (userManager.IsInRole(user.Id, "Operator")) { customers = northwindDb.Customers.Where(m => m.City == "USA").ToList(); } ViewBag.FullName = user.FullName + " (" + user.UserName + ") !"; return View(customers); }
public OrderController(IOrderService orderContext , MyIdentityDbContext user, IStatusService statusContext) { _orderContext = orderContext; _statusContext = statusContext; _user = user; }
public JsonResult SavePurchase(ProductReceive O) { bool status = false; if (ModelState.IsValid) { 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); O.DateReceived = DateTime.Now; O.UserId = user.Id; _productReceiveService.AddProductReceive(O); //Order order = new Order { OrderNo = O.OrderNo, OrderDate = O.OrderDate, Description = O.Description }; //foreach (var i in O.OrderDetails) //{ // // // // i.TotalAmount = // order.OrderDetails.Add(i); //} //dc.Orders.Add(order); //dc.SaveChanges(); status = true; } else { status = false; } return(new JsonResult { Data = new { status = status } }); }
public ActionResult Create([Bind(Include = "DateTransfered,FromBranchId,ToBranchId,UserId")] ProductTransferViewModel productTransferViewModel) { if (ModelState.IsValid) { 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 productTransfer = new ProductTransfer() { //FromBranchId =1, //productTransferViewModel.FromBranchId, //ToBranchId= 2, //productTransferViewModel.ToBranchId, FromBranchId = productTransferViewModel.FromBranchId, ToBranchId = productTransferViewModel.ToBranchId, UserId = user.Id, DateTransfered = DateTime.Now }; _productTransferService.AddProductTransfer(productTransfer); return(RedirectToAction("Create", "ProductTransfers", new { id = productTransfer.ProductTransferId })); } return(View(productTransferViewModel)); }
public ActionResult Index() { 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); DbDataEntities dbTest = new DbDataEntities(); List <Customer> model = null; if (userManager.IsInRole(user.Id, "Administrator")) { model = dbTest.Customers.ToList(); } if (userManager.IsInRole(user.Id, "Operator")) { model = dbTest.Customers.Where(c => c.Country == "USA").ToList(); } ViewBag.FullName = user.FullName; return(View(model)); }
public HomeController() { MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); }
public JsonResult SaveTransfer(ProductTransfer O) { bool status = false; if (ModelState.IsValid) { 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); O.DateTransfered = DateTime.Now; O.UserId = user.Id; _productTransferService.AddProductTransfer(O); status = true; } else { status = false; } return(new JsonResult { Data = new { status = status } }); }
public AuthController( UserManager <AppUser> userManager, IConfiguration configuration, MyIdentityDbContext userDbContext, RoleManager <IdentityRole> roleManager, IPrivateCustomerService privateContext, ICitizenshipService citizenshipContext, ICityService cityContext, IOfficeService officeContext, IBalanceService balanceContext, IBusinessCustomerService businessContext, IJwtAuthManager jwtAuthManager ) { _userManager = userManager; _configuration = configuration; _privateContext = privateContext; _userDbContext = userDbContext; _roleManager = roleManager; _citizenshipContext = citizenshipContext; _cityContext = cityContext; _officeContext = officeContext; _balanceContext = balanceContext; _businessContext = businessContext; _jwtAuthManager = jwtAuthManager; }
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)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); RoleManager <MyIdentityRole> roleManager = new RoleManager <MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole newRole = new MyIdentityRole("Administrator", "јдминистратор обладает полными правами в системе"); roleManager.Create(newRole); } if (!roleManager.RoleExists("AdminD")) { MyIdentityRole newRole = new MyIdentityRole("AdminD", "ќператоры могут только добавл¤ть и измен¤ть данные в системе"); roleManager.Create(newRole); } if (!roleManager.RoleExists("Client")) { MyIdentityRole newRole = new MyIdentityRole("Client", "Ёто клиент, он может покупать"); roleManager.Create(newRole); } }
public WaitingInvoiceController(ICargoService cargoContext , MyIdentityDbContext user, IStatusService statusContext, IWebHostEnvironment env) { _cargoContext = cargoContext; _statusContext = statusContext; _env = env; _user = user; }
public UsersController(UserManager <AppUser> userManager, IBusinessCustomerService businessContext, IPrivateCustomerService privateContext, RoleManager <IdentityRole> roleManager, MyIdentityDbContext userDbContext) { _userManager = userManager; _roleManager = roleManager; _userDbContext = userDbContext; _privateContext = privateContext; _businessContext = businessContext; }
/// <summary> /// 返回<see cref="MyUserManager"/>的实例,用来操作和管理用户。它需要传入OwinContext对象,通过该上下文对象,获取到存储在Owin环境字典中的Database Context实例。 /// </summary> /// <param name="options"></param> /// <param name="context"></param> /// <returns></returns> public static MyUserManager Create( IdentityFactoryOptions <MyUserManager> options, IOwinContext context) { MyIdentityDbContext DbContext = context.Get <MyIdentityDbContext>(); MyUserManager manager = new MyUserManager(new UserStore <MyUser>(DbContext)); return(manager); }
public AccountController() { MyIdentityDbContext db = new MyIdentityDbContext(); UserStore<MyIdentityUser> userStore = new UserStore<MyIdentityUser>(db); userManager = new UserManager<MyIdentityUser>(userStore); RoleStore<MyIdentityRole> roleStore = new RoleStore<MyIdentityRole>(db); roleManager = new RoleManager<MyIdentityRole>(roleStore); }
public AuthenticationAPIController() { MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); roleManager = new RoleManager <MyIdentityRole>(roleStore); }
private IdentityUserManager() : base(new UserStore <IdentityUser>(MyIdentityDbContext.Create())) { //...other code removed for brevity var dataProtectionProvider = Auth.DataProtectionProvider; if (dataProtectionProvider != null) { this.UserTokenProvider = new DataProtectorTokenProvider <IdentityUser>(dataProtectionProvider.Create("UserToken")); } }
public UserController(MyIdentityDbContext user, IHttpContextAccessor contextAccessor, IOfficeService officeContext, IWebHostEnvironment env, ICityService cityContext, UserManager <AppUser> userManager, IPrivateCustomerService privateContext, IBusinessCustomerService businesContext) { _privateContext = privateContext; _user = user; _businesContext = businesContext; _userManager = userManager; _cityContext = cityContext; _officeContext = officeContext; _contextAccessor = contextAccessor; _env = env; }
//Creation of an instance of our custom DbContext class //passe it to the constructor of UserStore and RoleStore classes //UserStore and RoleStore perform database storage and retrieval tasks public AccountController() { var db = new MyIdentityDbContext(); var userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); var roleStore = new RoleStore <MyIdentityRole>(db); roleManager = new RoleManager <MyIdentityRole>(roleStore); }
public AccountController(IBranchService branchService) { _branchService = branchService; MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); roleManager = new RoleManager <MyIdentityRole>(roleStore); }
// GET: ProductReceives/Create public ActionResult Create(int?id) { 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); if (id != null && id != 0) { var productReceive = _productReceiveService.Get(t => t.ProductReceiveId == id, null, "ProductReceiveLineItems").FirstOrDefault(); var productReceiveViewModel = new ProductReceiveViewModel() { BranchId = productReceive.BranchId, BranchName = productReceive.Branch.BranchName, DateReceived = productReceive.DateReceived, ProductReceiveId = productReceive.ProductReceiveId, UserId = productReceive.UserId, UserName = userManager.FindById(productReceive.UserId).FullName }; ViewBag.UserName = user.FullName; ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; ViewBag.ProductReceiveId = productReceive.ProductReceiveId; var productReceiveLineItemViewModels = new List <ProductReceiveLineItemViewModel>(); foreach (var productReceiveLineItem in productReceive.ProductReceiveLineItems) { var productReceiveLineItemviewModel = new ProductReceiveLineItemViewModel() { ProductReceiveLineItemId = productReceiveLineItem.ProductReceiveLineItemId, ProductId = productReceiveLineItem.ProductId, Productname = _productService.FindBy(s => s.ProductcId == productReceiveLineItem.ProductId).First().ProductName, Quantity = productReceiveLineItem.Quantity, UnitCost = productReceiveLineItem.UnitCost }; productReceiveLineItemViewModels.Add(productReceiveLineItemviewModel); } ViewData["ProductList"] = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName"); ViewData["BranchList"] = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName"); ViewBag.ProductReceiveLineItemViewModels = productReceiveLineItemViewModels; ViewBag.UserName = user.FullName; ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; return(View(productReceiveViewModel)); } ViewData["ProductList"] = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName"); ViewData["BranchList"] = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName"); ViewBag.UserName = user.FullName; ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; return(View()); }
public IIdentityManagerService Create() { #region MyIdentity Stuff MyIdentityDbContext db = new MyIdentityDbContext(); UserStore<MyIdentityUser> userStore = new UserStore<MyIdentityUser>(db); UserManager<MyIdentityUser> userManager = new UserManager<MyIdentityUser>(userStore); RoleStore<MyIdentityRole> roleStore = new RoleStore<MyIdentityRole>(db); RoleManager<MyIdentityRole> roleManager = new RoleManager<MyIdentityRole>(roleStore); #endregion var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<MyIdentityUser, string, MyIdentityRole, string>(userManager, roleManager); return new DisposableIdentityManagerService(svc, db); }
public ProductTransfersController(IProductTransferService productTransferService, IBranchService branchService, IProductService productService) { _productTransferService = productTransferService; _branchService = branchService; _productService = productService; MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); roleManager = new RoleManager <MyIdentityRole>(roleStore); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); AreaRegistration.RegisterAllAreas(); DependencyResolver.SetResolver(new NinjectDependencyResolver()); //log4net.Config.XmlConfigurator.Configure(); //DependencyResolver.Current.GetService<ILogger>(); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); RoleManager <MyIdentityRole> roleManager = new RoleManager <MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole newRole = new MyIdentityRole("Administrator", "Administrators can add, edit and delete data."); roleManager.Create(newRole); } if (!roleManager.RoleExists("SalesPerson")) { MyIdentityRole newRole = new MyIdentityRole("SalesPerson", "SalesPersons can only add or edit data."); roleManager.Create(newRole); } if (!roleManager.RoleExists("Cashier")) { MyIdentityRole newRole = new MyIdentityRole("Cashier", "Cashiers can only add or edit data."); roleManager.Create(newRole); } if (!roleManager.RoleExists("StoreKeeper")) { MyIdentityRole newRole = new MyIdentityRole("StoreKeeper", "StoreKeepers can only add or edit data."); roleManager.Create(newRole); } }
public SalesInvoicesController(ISalesInvoiceService salesInvoiceService, ICustomerService customerService, IBranchService branchService, IProductService productService) { _salesInvoiceService = salesInvoiceService; _customerService = customerService; _branchService = branchService; _productService = productService; MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); roleManager = new RoleManager <MyIdentityRole>(roleStore); }
public static dynamic GetUserRoleByID(string userid) { MyIdentityDbContext db = new MyIdentityDbContext(); UserStore <MyIdentityUser> userStore = new UserStore <MyIdentityUser>(db); userManager = new UserManager <MyIdentityUser>(userStore); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); roleManager = new RoleManager <MyIdentityRole>(roleStore); List <string> roles = userManager.GetRoles(userid).ToList(); if (roles.Count > 0) { return(roles[0]); } else { return(null); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); RoleManager <MyIdentityRole> roleManager = new RoleManager <MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole newRole = new MyIdentityRole("Administrator", "Administrators can add, edit and delete data."); roleManager.Create(newRole); } if (!roleManager.RoleExists("User")) { MyIdentityRole newRole = new MyIdentityRole("User", "Regular users."); roleManager.Create(newRole); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore<MyIdentityRole> roleStore = new RoleStore<MyIdentityRole>(db); RoleManager<MyIdentityRole> roleManager = new RoleManager<MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole role = new MyIdentityRole("Administrator", "Administrators can add, edit and delete all items."); roleManager.Create(role); } if (!roleManager.RoleExists("Operator")) { MyIdentityRole role = new MyIdentityRole("Operator", "Operator can only add or edit items."); roleManager.Create(role); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); //BundleConfig.RegisterBundles(BundleTable.Bundles); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); RoleManager <MyIdentityRole> roleManager = new RoleManager <MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole newRole = new MyIdentityRole("Administrator", "Administrators can add, edit and delete data."); roleManager.Create(newRole); } if (!roleManager.RoleExists("Operator")) { MyIdentityRole newRole = new MyIdentityRole("Operator", "Operators can only add or edit data."); roleManager.Create(newRole); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); MyIdentityDbContext db = new MyIdentityDbContext(); RoleStore <MyIdentityRole> roleStore = new RoleStore <MyIdentityRole>(db); RoleManager <MyIdentityRole> roleManager = new RoleManager <MyIdentityRole>(roleStore); if (!roleManager.RoleExists("Administrator")) { MyIdentityRole newRole = new MyIdentityRole("Administrator", "јдминистратор обладает полными правами в системе"); roleManager.Create(newRole); } if (!roleManager.RoleExists("Client")) { MyIdentityRole newRole = new MyIdentityRole("Client", " лиент может просматривать информацию"); roleManager.Create(newRole); } }
public ActionResult Create(ProductReceiveViewModel productReceiveViewModel) { if (ModelState.IsValid) { 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 productReceive = new ProductReceive() { BranchId = user.BranchId, UserId = user.Id, DateReceived = DateTime.Now }; _productReceiveService.AddProductReceive(productReceive); return(RedirectToAction("Create", "ProductReceives", new { id = productReceive.ProductReceiveId })); } return(View(productReceiveViewModel)); }
public AccountController() { _dbContext=new MyIdentityDbContext(); _repository=new MyRepository<MyIdentityDbContext, MyUser, long>(_dbContext); }
public QuantriBaseController() { context = new MyIdentityDbContext(); context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); }
// GET: SalesInvoices/Create public ActionResult Create(int?id, int?salesType) { 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); if (id != null && id != 0) { var salesInvoice = _salesInvoiceService.Get(t => t.SalesInvoiceId == id, null, "SalesLineItems").FirstOrDefault(); var salesInvoiceViewModel = new SalesInvoiceViewModel() { BranchId = salesInvoice.BranchId, CustomerId = salesInvoice.CustomerId, CustomerName = salesInvoice.Customer.FirstName + " " + salesInvoice.Customer.LastName, BranchName = salesInvoice.Branch.BranchName, DateSold = salesInvoice.DateSold, ReferenceNo = salesInvoice.ReferenceNo, SalesInvoiceId = salesInvoice.SalesInvoiceId, SalesType = salesInvoice.SalesType, UserId = salesInvoice.UserId, UserName = userManager.FindById(salesInvoice.UserId).FullName, Status = salesInvoice.Status }; ViewBag.UserName = user.FullName; ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; ViewBag.CustomerList = new SelectList(_customerService.GetAllCustomers(), "CustomerId", "FirstName", salesInvoice.CustomerId); ViewBag.BranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName", salesInvoice.BranchId); ViewBag.SalesInvoiceId = salesInvoice.SalesInvoiceId; var salesLineItemviewModels = new List <SalesInvoiceLineItemViewModel>(); foreach (var salesLineItem in salesInvoice.SalesLineItems) { var salesLineItemviewModel = new SalesInvoiceLineItemViewModel() { SalesLineItemId = salesLineItem.SalesLineItemId, ProductId = salesLineItem.ProductId, Productname = _productService.FindBy(s => s.ProductcId == salesLineItem.ProductId).First().ProductName, Quantity = salesLineItem.Quantity, UnitPrice = salesLineItem.UnitPrice }; salesLineItemviewModels.Add(salesLineItemviewModel); } ViewData["CustomerList"] = new SelectList(_customerService.GetAllCustomers(), "CustomerId", "FirstName", salesInvoice.CustomerId); ViewData["ProductList"] = new SelectList(_productService.GetAllProducts(), "ProductcId", "ProductName", salesInvoice.CustomerId); ViewBag.SalesLineItemViewModels = salesLineItemviewModels; ViewBag.UserName = user.FullName; ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; ViewBag.SalesType = salesInvoice.SalesType; return(View(salesInvoiceViewModel)); } ViewBag.UserName = user.FullName; ViewBag.BranchName = _branchService.FindById(user.BranchId).BranchName; if (salesType == 0) { ViewBag.CustomerList = new SelectList(_customerService.Get(t => t.Trusted).ToList(), "CustomerId", "FirstName"); } else { ViewBag.CustomerList = new SelectList(_customerService.GetAllCustomers(), "CustomerId", "FirstName"); } ViewBag.SalesType = salesType; ViewBag.BranchList = new SelectList(_branchService.GetAllBranches(), "BranchId", "BranchName"); return(View()); }