public ActionResult Create([Bind(Include = "id,customerid,Date,description,Ammount")] Payment payment) { if (ModelState.IsValid) { db.Payments.Add(payment); db.SaveChanges(); var customer = (from cust in db.Customers where cust.id == payment.customerid select cust).FirstOrDefault(); customer.ammount = customer.ammount - payment.Ammount; db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); Global.Money = Global.Money + payment.Ammount; Transaction transaction = new Transaction(); transaction.Ammount = payment.Ammount; transaction.Balance = customer.ammount; transaction.Date = payment.Date; transaction.Description = ""; transaction.Payment = payment; transaction.Paymentid = payment.id; transaction.Customer = customer; transaction.Customerid = customer.id; transaction.type = TransactionType.Debit; db.Transactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.customerid = new SelectList(db.Customers, "id", "name", payment.customerid); return(View(payment)); }
public ActionResult Create([Bind(Include = "id,customerid,itemid,returnDate,ammount,description")] ReturnItem returnItem) { if (ModelState.IsValid) { db.ReturnItems.Add(returnItem); db.SaveChanges(); var itm = (from item in db.item where item.id == returnItem.itemid select item).FirstOrDefault(); Global.Money = Global.Money - returnItem.ammount; Customer customer = db.Customers.Where(cus => cus.id == returnItem.customerid).FirstOrDefault(); customer.ammount = customer.ammount - returnItem.ammount; db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); Transaction transaction = new Transaction(); transaction.Ammount = returnItem.ammount; transaction.Balance = customer.ammount; transaction.Date = returnItem.returnDate; transaction.Description = "Returned"; transaction.Customer = customer; transaction.Customerid = customer.id; transaction.type = TransactionType.Debit; db.Transactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.customerid = new SelectList(db.Customers, "id", "name", returnItem.customerid); ViewBag.itemid = new SelectList(db.item, "id", "name", returnItem.itemid); return(View(returnItem)); }
public ActionResult Delete(int id, Customer c1) { Customer c = context.Customers.Where(x => x.CustomerId == id).SingleOrDefault(); context.Customers.Remove(c); context.SaveChanges(); return(RedirectToAction("Index")); }
public void AddBanner(MainBanner banner) { using (_db) { _db.MainBanners.Add(banner); _db.SaveChanges(); } }
public void AddTour(Tour tour) { using (_db) { _db.Entry(tour.Company).State = EntityState.Unchanged; _db.Tours.Add(tour); _db.SaveChanges(); } }
public void AddFeedback(Feedback feedback) { using (_db) { _db.Entry(feedback.Tour).State = EntityState.Unchanged; _db.Feedbacks.Add(feedback); _db.SaveChanges(); } }
public void AddCompany(Company company) { using (_db) { _db.Entry(company.City).State = EntityState.Unchanged; _db.Companies.Add(company); _db.SaveChanges(); } }
public ActionResult Create([Bind("ProductName", "ProductPrice", "ProductQuantity", "ProductSize")] Product c) { if (ModelState.IsValid) { context.Products.Add(c); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(c)); }
public ActionResult Create([Bind("CategoryName", "CategoryDescription")] Category C) { if (ModelState.IsValid) { context.Categories.Add(C); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(C)); }
public ActionResult Create([Bind("VendorName", "VendorEmail", "VendorPhoneNo")] Vendor V) { if (ModelState.IsValid) { context.Vendors.Add(V); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(V)); }
public ActionResult Create([Bind("ProductName", "ProductPrice", "ProductImage", "ProductQuantity", "ProductSize", "ProductDescription", "CategoryId", "VendorId", "BrandId")] Product c) { if (ModelState.IsValid) { context.Products.Add(c); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(c)); }
public void Adduser(User user) { using (_db) { _db.Entry(user.Role).State = EntityState.Unchanged; _db.Entry(user.City).State = EntityState.Unchanged; _db.Users.Add(user); _db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "id,name,Location,Email,mobile,company,ammount")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "id,name,price,Emp_Charges,description,borderframe,BorderFrame_quantity,Acrylic,shell_quantity,raison,Mat300,Mat450,cobalt,Mekb,Titanium,bursh,JelCoat,Aerosel,BrushCleaner,plastic,colour,Plasticparis,nut,bolts,plastic_nut_Bolts,khrpaichy,Polish,Kapra,bowl,cuttingcream,dori,cement")] Product product) { if (ModelState.IsValid) { db.product.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create(Manager B) { if (ModelState.IsValid) { context.Managers.Add(B); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(B)); }
public ActionResult Create([Bind(Include = "id,name,description")] ExpenseType expenseType) { if (ModelState.IsValid) { db.expenseType.Add(expenseType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(expenseType)); }
public ActionResult Create([Bind(Include = "id,name,description")] Entity entity) { if (ModelState.IsValid) { db.entity.Add(entity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(entity)); }
public ActionResult Create([Bind("BrandName", "BrandDescription")] Brand B) { if (ModelState.IsValid) { context.Brands.Add(B); context.SaveChanges(); return(RedirectToAction("Index")); } return(View(B)); }
public ActionResult Create([Bind(Include = "id,name,description")] Colour colour) { if (ModelState.IsValid) { db.colour.Add(colour); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(colour)); }
public ActionResult Create([Bind(Include = "id,Customerid,Orderid,Paymentid,Ammount,type,Balance,Description,Date")] Transaction transaction) { if (ModelState.IsValid) { db.Transactions.Add(transaction); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Customerid = new SelectList(db.Customers, "id", "name", transaction.Customerid); ViewBag.Orderid = new SelectList(db.order, "id", "description", transaction.Orderid); ViewBag.Paymentid = new SelectList(db.Payments, "id", "description", transaction.Paymentid); return(View(transaction)); }
// GET: Items/Create public int colourCheckAndMake(string color) { var col = (from colour in db.colour where colour.name.Equals(color) select colour).FirstOrDefault(); Colour colr = col; if (col == null) { colr = new Colour(); colr.name = color; db.colour.Add(colr); db.SaveChanges(); } return(colr.id); }
public ActionResult Create([Bind(Include = "id,typeId,entityId,Date,description,Ammount")] Expense expense) { if (ModelState.IsValid) { db.expense.Add(expense); db.SaveChanges(); Global.Money = Global.Money - expense.Ammount; return(RedirectToAction("Index")); } ViewBag.entityId = new SelectList(db.entity, "id", "name", expense.entityId); ViewBag.typeId = new SelectList(db.expenseType, "id", "name", expense.typeId); return(View(expense)); }
public void GetCustomerByUserNameWorks() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// Cache setup //var memoryCache = serviceProvider.GetService<IMemoryCache>(); //IMemoryCache _cache = RevatureP1.UtilMethods.InitializeCacheIfNeeded(memoryCache); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// Cache populating //_cache.Set("thisCustomer", testCustomer); //// DbContext populating Customer testCustomer = new Customer(); string testString = "testUserNameA"; testCustomer.UserName = testString; testContext.Add(testCustomer); // already done testContext.SaveChanges(); // Arrange Customer gottenCustomer = RevatureP1.UtilMethods.GetCustomerByUserName(testString, testContext); var resultVal = gottenCustomer.UserName; var expectedVal = testString; //Assert Assert.Equal(expectedVal, resultVal); }
public void GetLocationByIdHandlesFailureCorrectly() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating Location testLocation = new Location(); int testInt = 12; string testString = "testVal"; testLocation.LocationId = testInt; testLocation.LocationAddress = testString; testContext.Add(testLocation); // Already done testContext.SaveChanges(); // Arrange Location gottenLocation = RevatureP1.UtilMethods.GetLocationById(111, testContext); var resultVal = gottenLocation.LocationAddress; var expectedVal = new Location().LocationAddress; //Assert Assert.Equal(expectedVal, resultVal); }
public void GetProductByIdHandlesFailureCorrectly() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating Product testProduct = new Product(); int testInt = 15; string testString = "testVal"; testProduct.ProductId = testInt; testProduct.Name = testString; testContext.Add(testProduct); testContext.SaveChanges(); // Arrange Product gottenProduct = RevatureP1.UtilMethods.GetProductById(2, testContext); var resultVal = gottenProduct.Name; var expectedVal = new Product().Name; //Assert Assert.Equal(expectedVal, resultVal); }
public void GetStockItemByIdHandlesFailureCorrectly() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating StockItem testStockItem = new StockItem(); int testInt = 102; int testInt2 = 202; int testInt3 = 302; //string testString = "testVal"; testStockItem.LocationId = testInt; testStockItem.ProductId = testInt2; testStockItem.StockCount = testInt3; testContext.Add(testStockItem); testContext.SaveChanges(); // Arrange StockItem gottenStockItem = RevatureP1.UtilMethods.GetStockItemByIds(4, 4, testContext); var resultVal = gottenStockItem.StockCount; var expectedVal = new StockItem().StockCount; //Assert Assert.Equal(expectedVal, resultVal); }
public void ProductCountReturnsFalseWhenItShould() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating StockItem testStockItem = new StockItem(); int testInt = 104; int testInt2 = 204; int testInt3 = 304; int testint4 = 404; //string testString = "testVal"; testStockItem.LocationId = testInt; testStockItem.ProductId = testInt2; testStockItem.StockCount = testInt3; testContext.Add(testStockItem); testContext.SaveChanges(); // Arrange bool enoughInStock = RevatureP1.UtilMethods.CheckProductCount(testInt, testInt2, testint4, testContext); var resultVal = enoughInStock; var expectedVal = false; //Assert Assert.Equal(expectedVal, resultVal); }
public void BuildStockItemViewModelFromLocStockWorks() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating Location testLocation = new Location(); StockItem testStockItem = new StockItem(); testStockItem.DiscountPercent = 50; Product testProduct = new Product(); testProduct.BasePrice = 6; testContext.Add(testProduct); testContext.SaveChanges(); // Arrange StockItemViewModel testStockItemViewModel = RevatureP1.UtilMethods.BuildStockItemViewModelFromLocStock( testLocation, testStockItem, testContext); var resultVal = testStockItemViewModel.SaleString; var expectedVal = "50% Off!"; //Assert Assert.Equal(expectedVal, resultVal); }
public ActionResult Create(ProductDetail product) { _context.ProductDetails.Add(product); // Data Binding //_context.Set<ProductDetail>().AddOrUpdate(product); _context.SaveChanges(); //try //{ // _context.SaveChanges(); //} //catch (DbEntityValidationException e) //{ // Console.WriteLine(e); //} return(RedirectToAction("Index", "ProductDetails")); }
public void GetCustomerByUserNameHandlesFailuteCorrectly() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating Customer testCustomer = new Customer(); string testString = "testUserName"; testCustomer.UserName = testString; testContext.Add(testCustomer); testContext.SaveChanges(); // Arrange Customer gottenCustomer = RevatureP1.UtilMethods.GetCustomerByUserName("otherName", testContext); var resultVal = gottenCustomer.UserName; var expectedVal = new Customer().UserName; //Assert Assert.Equal(expectedVal, resultVal); }