public ActionResult Create([FromBody] StoreQueueViewModel vm) { var sq = vm.ToStoreQueue(); var res = _bo.Create(sq); return(res.Success ? Ok() : InternalServerError()); }
public ActionResult Update([FromBody] StoreQueueViewModel sq) { var currentResult = _bo.Read(sq.Id); if (!currentResult.Success) { return(InternalServerError()); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Quantity == sq.Quantity) { return(NotModified()); } if (current.Quantity != sq.Quantity) { current.Quantity = sq.Quantity; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(InternalServerError()); } return(Ok()); }
public async Task <IActionResult> Edit(Guid id, StoreQueueViewModel vm) { 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); Draw("Edit", "fa-edit"); return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } } return(RedirectToAction(nameof(Index))); }
public ActionResult<StoreQueueViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) return NotFound(); var sqvm = new StoreQueueViewModel(); sqvm.Id = res.Result.Id; sqvm.EstablishmentId= res.Result.EstablishmentId; sqvm.Quantity = res.Result.Quantity; return sqvm; } else return StatusCode((int)HttpStatusCode.InternalServerError); }
public ActionResult <List <StoreQueueViewModel> > List() { var res = _bo.List(); if (!res.Success) { return(InternalServerError()); } var list = new List <StoreQueueViewModel>(); foreach (var item in res.Result) { list.Add(StoreQueueViewModel.Parse(item)); } return(list); }
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 getDrOperation = await _ebo.ReadAsync(getOperation.Result.EstablishmentId); if (!getDrOperation.Success) { return(OperationErrorBackToIndex(getDrOperation.Exception)); } if (getDrOperation.Result == null) { return(RecordNotFound()); } var getCOperation = await _cbo.ReadAsync(getDrOperation.Result.CompanyId); if (!getCOperation.Success) { return(OperationErrorBackToIndex(getCOperation.Exception)); } if (getCOperation.Result == null) { return(RecordNotFound()); } var vm = StoreQueueViewModel.Parse(getOperation.Result); ViewData["Company"] = CompanyViewModel.Parse(getCOperation.Result); ViewData["Establishment"] = EstablishmentViewModel.Parse(getDrOperation.Result); Draw("Details", "fa-search"); return(View(vm)); }
public ActionResult Update([FromBody] StoreQueueViewModel storeQueue) { var currentRes = _bo.Read(storeQueue.Id); if (!currentRes.Success) return StatusCode((int)HttpStatusCode.InternalServerError); var current = currentRes.Result; if (current == null) return NotFound(); if (current.EstablishmentId == storeQueue.EstablishmentId && current.Quantity == storeQueue.Quantity) return StatusCode((int)HttpStatusCode.NotModified); if (current.EstablishmentId != storeQueue.EstablishmentId) current.EstablishmentId = storeQueue.EstablishmentId; if (current.Quantity != storeQueue.Quantity) current.Quantity = storeQueue.Quantity; var updateResult = _bo.Update(current); if (!updateResult.Success) return StatusCode((int)HttpStatusCode.InternalServerError); return Ok(); }
public ActionResult <StoreQueueViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var vm = StoreQueueViewModel.Parse(res.Result); return(vm); } else { return(InternalServerError()); } }
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 = StoreQueueViewModel.Parse(getOperation.Result); var listDrOperation = await _ebo.ListNotDeletedAsync(); if (!listDrOperation.Success) { return(OperationErrorBackToIndex(listDrOperation.Exception)); } var drList = new List <SelectListItem>(); foreach (var item in listDrOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Address }; if (item.Id == vm.EstablishmentId) { listItem.Selected = true; } drList.Add(listItem); } ViewBag.Establishments = drList; Draw("Edit", "fa-edit"); return(View(vm)); }
public async Task <IActionResult> Create(StoreQueueViewModel vm) { if (ModelState.IsValid) { var model = vm.ToStoreQueue(); 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> Index() { var listOperation = await _bo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <StoreQueueViewModel>(); foreach (var item in listOperation.Result) { lst.Add(StoreQueueViewModel.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 drList = await GetEstablishmentViewModels(listOperation.Result.Select(x => x.EstablishmentId).Distinct().ToList()); var cList = await GetCompanyViewModels(listEOperation.Result.Select(x => x.CompanyId).Distinct().ToList()); ViewData["Companies"] = cList; ViewData["Establishments"] = drList; ViewData["Title"] = "Store Queues"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }
public ActionResult Create([FromBody]StoreQueueViewModel vm) { var storeQueue = vm.ToStoreQueue(); var res = _bo.Create(storeQueue); return StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.InternalServerError); }