public ActionResult Update(Furniture furniture) { if (ModelState.IsValid) { _db.Update(furniture); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } return(View(furniture)); }
public FurnitureItemModel UpdateFurnitureItem(UpdateFurnitureDto dto) { return(ProtectedExecute <UpdateFurnitureDto, FurnitureItemModel>(furnitureDto => { AdminService.CheckActiveAdmin(furnitureDto.AdminSession); FurnitureItemModel model = Mapper.Map <UpdateFurnitureDto, FurnitureItemModel>(furnitureDto); IEnumerable <UsedPartModel> partsToAdd = furnitureDto.UsedPartsToAdd.Aggregate( new List <UsedPartModel>(), (acc, parts) => acc.Concat(Enumerable.Repeat(new UsedPartModel(parts.PartId.GetValueOrDefault()), parts.Count.GetValueOrDefault())).ToList() ); return FurnitureRepo.Update(model.Id, model, furnitureDto.UsedPartsToRemove, partsToAdd); }, dto)); }
public ActionResult CompletePurchase(ShoppingCart cart) { if (cart.Items.Count() == 0) { ModelState.AddModelError("", "Cart is empty!"); } if (ModelState.IsValid) { Bill bill = new Bill(); foreach (var item in cart.Items) { BillItem billItem = new BillItem { Furniture = item.Furniture.Name, FurnitureCategory = item.Furniture.Category.Name, Amount = item.Quantity, Price = item.Furniture.Price * item.Quantity, FurnitureShop = item.Furniture.FurnitureSalon.Name }; Furniture furniture = _db.GetById(item.Furniture.FurnitureId); furniture.Amount = furniture.Amount - billItem.Amount; _db.Update(furniture); foreach (var k in cart.ViewItems) { k.Furniture.Amount = furniture.Amount; } bill.BillItems.Add(billItem); } bill.Tax = Tax.RegularTax; var subTotal = bill.BillItems.Aggregate(new decimal { }, (result, item) => { result += item.Price; return(result); }); bill.TotalPrice = subTotal + (subTotal * bill.Tax); bill.TimeOfPurchase = DateTime.Now; string firstName = _dbUsers.GetAll().Where(x => x.UserName.Equals(User.Identity.Name)).Select(x => x.FirstName).First(); string lastName = _dbUsers.GetAll().Where(x => x.UserName.Equals(User.Identity.Name)).Select(x => x.LastName).First(); bill.Buyer = firstName + " " + lastName; _dbBill.Add(bill); cart.Clear(); return(View("OrderSubmited")); } return(RedirectToRoute(new { controller = "ShoppingCart", action = "Index" })); }