public ActionResult Create([FromBody] ShoppingBasketViewModel vm) { var shoppingBasket = vm.ToShoppingBasket(); var res = _bo.Create(shoppingBasket); return(StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.InternalServerError)); }
public async Task <IViewComponentResult> InvokeAsync() { ISession session = services.GetRequiredService <IHttpContextAccessor>()?.HttpContext.Session; if (session.GetString("ShoppingBasketId") == null) { session.SetString("ShoppingBasketId", Guid.NewGuid().ToString()); } string BasketStringId = session.GetString("ShoppingBasketId"); Guid BasketId = Guid.Parse(BasketStringId); IEnumerable <ShoppingBasketItem> shoppingBasketItems = await this.manager.GetShoppingBasketItemsForShoppingBasket(BasketId); ShoppingBasketViewModel model = new ShoppingBasketViewModel() { ShoppingBasket = new ShoppingBasket() { Id = BasketId, ShoppingBasketItems = shoppingBasketItems.ToList() }, ShoppingBasketTotal = await this.manager.GetTotalAsync(BasketId) }; return(this.View(model)); }
public ActionResult Update([FromBody] ShoppingBasketViewModel shoppingBasket) { var currentRes = _bo.Read(shoppingBasket.Id); if (!currentRes.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } var current = currentRes.Result; if (current == null) { return(NotFound()); } if (current.ProfileId == shoppingBasket.ProfileId) { return(StatusCode((int)HttpStatusCode.NotModified)); } if (current.ProfileId != shoppingBasket.ProfileId) { current.ProfileId = shoppingBasket.ProfileId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok()); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <ShoppingBasketViewModel>(); foreach (var item in listOperation.Result) { lst.Add(ShoppingBasketViewModel.Parse(item)); } var pList = await GetProfileViewModels(listOperation.Result.Select(x => x.ProfileId).Distinct().ToList()); ViewData["Profiles"] = pList; ViewData["Title"] = "ShoppingBaskets"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }
public async Task <IActionResult> OrderAsync(string Email, string prname) { var product = db.fish.AsNoTracking(); var count = basket.basket.ToList(); Fish fish = new Fish(); foreach (var item in product) { if (item.name == prname) { fish.name = item.name; fish.price = item.price; fish.unit = item.unit; fish.Description = item.Description; } } User user = await _userManager.FindByEmailAsync(Email); if (user == null) { return(NotFound()); } ShoppingBasketViewModel model = new ShoppingBasketViewModel { Id = count.Count().ToString(), Name = user.Name, Email = user.Email, PhoneNumber = user.NumberPhone, Price = fish.price, ProductName = fish.name, unit = fish.unit }; return(View(model)); }
public async Task <IActionResult> Edit(Guid id, ShoppingBasketViewModel vm) { var listROperation = await _pbo.ListNotDeletedAsync(); if (!listROperation.Success) { return(OperationErrorBackToIndex(listROperation.Exception)); } var pList = new List <SelectListItem>(); foreach (var item in listROperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.VatNumber.ToString() }; if (item.Id == vm.ProfileId) { listItem.Selected = true; } pList.Add(listItem); } ViewBag.Regions = pList; Draw("Edit", "fa-edit"); if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync(id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result = vm.ToModel(result); var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } } return(RedirectToAction(nameof(Index))); }
private async Task <List <ShoppingBasketViewModel> > GetShoppingBasketViewModels(List <Guid> ids) { var filterOperation = await _sbbo.FilterAsync(x => ids.Contains(x.Id)); var drList = new List <ShoppingBasketViewModel>(); foreach (var item in filterOperation.Result) { drList.Add(ShoppingBasketViewModel.Parse(item)); } return(drList); }
// // GET: /PizzaBasket/ public ActionResult Index() { ShoppingBasketHelper helper = new ShoppingBasketHelper(); // Set up our ViewModel var viewModel = new ShoppingBasketViewModel { BasketItems = helper.GetCartItems(), BasketTotal = helper.GetTotal() }; // Return the view return(View(viewModel)); }
public async Task <ActionResult> Index() { IEnumerable <ShoppingBasketItem> shoppingBasketItems = await this.manager.GetShoppingBasketItemsForShoppingBasket(base.BasketId); ShoppingBasketViewModel model = new ShoppingBasketViewModel() { ShoppingBasket = new ShoppingBasket() { ShoppingBasketItems = shoppingBasketItems.ToList(), Id = base.BasketId }, ShoppingBasketTotal = await this.manager.GetTotalAsync(base.BasketId) }; return(this.View(model)); }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(RecordNotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var vm = ShoppingBasketViewModel.Parse(getOperation.Result); var listROperation = await _pbo.ListNotDeletedAsync(); if (!listROperation.Success) { return(OperationErrorBackToIndex(listROperation.Exception)); } var pList = new List <SelectListItem>(); foreach (var item in listROperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.VatNumber.ToString() }; if (item.Id == vm.ProfileId) { listItem.Selected = true; } pList.Add(listItem); } ViewBag.Profiles = pList; Draw("Edit", "fa-edit"); return(View(vm)); }
public IActionResult Edit(string id) { var basket = shbasket.basket.ToList(); ShoppingBasketViewModel choosenItem = new ShoppingBasketViewModel(); foreach (var item in basket) { if (item.Id == id) { ShoppingBasketViewModel model = new ShoppingBasketViewModel { Id = item.Id, Count = item.Count, Name = item.Name, Email = item.Email, PhoneNumber = item.PhoneNumber, Price = item.Price, ProductName = item.ProductName, unit = item.unit }; choosenItem = model; } } return(View(choosenItem)); }
public ActionResult <ShoppingBasketViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var sbvm = new ShoppingBasketViewModel(); sbvm.Id = res.Result.Id; sbvm.ProfileId = res.Result.ProfileId; return(sbvm); } else { return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public async Task <IActionResult> Create(ShoppingBasketViewModel vm) { var listROperation = await _pbo.ListNotDeletedAsync(); if (!listROperation.Success) { return(OperationErrorBackToIndex(listROperation.Exception)); } var pList = new List <SelectListItem>(); foreach (var item in listROperation.Result) { pList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.VatNumber.ToString() }); } ViewBag.Profiles = pList; Draw("Create", "fa-plus"); if (ModelState.IsValid) { var model = vm.ToShoppingBasket(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } else { return(OperationSuccess("The record was successfuly created")); } } return(View(vm)); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(RecordNotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var getROperation = await _pbo.ReadAsync(getOperation.Result.ProfileId); if (!getROperation.Success) { return(OperationErrorBackToIndex(getROperation.Exception)); } if (getROperation.Result == null) { return(RecordNotFound()); } var vm = ShoppingBasketViewModel.Parse(getOperation.Result); ViewData["Profile"] = ProfileViewModel.Parse(getROperation.Result); Draw("Details", "fa-search"); return(View(vm)); }
public IActionResult Edit(ShoppingBasketViewModel model) { if (ModelState.IsValid) { var item = shbasket.basket.AsNoTracking().ToList(); ShoppingBasketViewModel selectedObj = new ShoppingBasketViewModel(); foreach (var obj in item) { if (obj.Id == model.Id) { selectedObj = obj; } } if (item != null) { selectedObj.Id = model.Id; selectedObj.Count = model.Count; shbasket.Update(selectedObj); shbasket.SaveChanges(); } } return(RedirectToAction("MyOrders")); }
private async Task <ShoppingBasketViewModel> GetShoppingBasketViewModel(Guid id) { var getOperation = await _sbbo.ReadAsync(id); return(ShoppingBasketViewModel.Parse(getOperation.Result)); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <ProductUnitViewModel>(); foreach (var item in listOperation.Result) { lst.Add(ProductUnitViewModel.Parse(item)); } var listEOperation = await _ebo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var elst = new List <EstablishmentViewModel>(); foreach (var item in listEOperation.Result) { elst.Add(EstablishmentViewModel.Parse(item)); } var listSBOperation = await _sbbo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var sblst = new List <ShoppingBasketViewModel>(); foreach (var item in listSBOperation.Result) { sblst.Add(ShoppingBasketViewModel.Parse(item)); } var eList = await GetEstablishmentViewModels(listOperation.Result.Select(x => x.EstablishmentId).Distinct().ToList()); var sbList = await GetShoppingBasketViewModels(listOperation.Result.Select(x => x.ShoppingBasketId).Distinct().ToList()); var pmList = await GetProductModelViewModels(listOperation.Result.Select(x => x.ProductModelId).Distinct().ToList()); var cList = await GetCompanyViewModels(listEOperation.Result.Select(x => x.CompanyId).Distinct().ToList()); var pList = await GetProfileViewModels(listSBOperation.Result.Select(x => x.ProfileId).Distinct().ToList()); ViewData["Profiles"] = pList; ViewData["Companies"] = cList; ViewData["Establishments"] = eList; ViewData["ShoppingBaskets"] = sbList; ViewData["ProductModels"] = pmList; ViewData["Title"] = "Product Units"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }
public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var getEOperation = await _ebo.ReadAsync(getOperation.Result.EstablishmentId); if (!getEOperation.Success) { return(OperationErrorBackToIndex(getEOperation.Exception)); } if (getEOperation.Result == null) { return(RecordNotFound()); } var getSBOperation = await _sbbo.ReadAsync(getOperation.Result.ShoppingBasketId); if (!getSBOperation.Success) { return(OperationErrorBackToIndex(getSBOperation.Exception)); } if (getSBOperation.Result == null) { return(RecordNotFound()); } var getPMOperation = await _pmbo.ReadAsync(getOperation.Result.ProductModelId); if (!getPMOperation.Success) { return(OperationErrorBackToIndex(getPMOperation.Exception)); } if (getPMOperation.Result == null) { return(RecordNotFound()); } var getPOperation = await _pbo.ReadAsync(getSBOperation.Result.ProfileId); if (!getPOperation.Success) { return(OperationErrorBackToIndex(getPOperation.Exception)); } if (getPOperation.Result == null) { return(RecordNotFound()); } var getCOperation = await _cbo.ReadAsync(getEOperation.Result.CompanyId); if (!getCOperation.Success) { return(OperationErrorBackToIndex(getCOperation.Exception)); } if (getCOperation.Result == null) { return(RecordNotFound()); } var vm = ProductUnitViewModel.Parse(getOperation.Result); ViewData["Profile"] = ProfileViewModel.Parse(getPOperation.Result); ViewData["Company"] = CompanyViewModel.Parse(getCOperation.Result); ViewData["Establishment"] = EstablishmentViewModel.Parse(getEOperation.Result); ViewData["ShoppingBasket"] = ShoppingBasketViewModel.Parse(getSBOperation.Result); ViewData["ProductModel"] = ProductModelViewModel.Parse(getPMOperation.Result); Draw("Details", "fa-search"); return(View(vm)); }
public IActionResult Order(ShoppingBasketViewModel Orders) { basket.basket.Add(Orders); basket.SaveChanges(); return(RedirectToAction("ThanksOrder")); }