public ActionResult Create([FromBody] EstablishmentViewModel vm) { var establishment = vm.ToModel(); var res = _bo.Create(establishment); return(StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.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 = EstablishmentViewModel.Parse(getOperation.Result); var listROperation = await _rbo.ListNotDeletedAsync(); if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception); var rList = new List<SelectListItem>(); foreach (var item in listROperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.RegionId) listItem.Selected = true; rList.Add(listItem); } ViewBag.Regions = rList; var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception); var cList = new List<SelectListItem>(); foreach (var item in listCOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.CompanyId) listItem.Selected = true; cList.Add(listItem); } ViewBag.Companies = cList; Draw("Edit", "fa-edit"); return View(vm); }
public ActionResult <EstablishmentViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var evm = new EstablishmentViewModel(); evm.Id = res.Result.Id; evm.Address = res.Result.Address; evm.ClosingDays = res.Result.ClosingDays; evm.ClosingHours = res.Result.ClosingHours; evm.OpeningHours = res.Result.OpeningHours; evm.RegionId = res.Result.RegionId; evm.CompanyId = res.Result.CompanyId; return(evm); } else { return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
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 _rbo.ReadAsync(getOperation.Result.RegionId); if (!getROperation.Success) return OperationErrorBackToIndex(getROperation.Exception); if (getROperation.Result == null) return RecordNotFound(); var getCOperation = await _cbo.ReadAsync(getOperation.Result.CompanyId); if (!getCOperation.Success) return OperationErrorBackToIndex(getCOperation.Exception); if (getCOperation.Result == null) return RecordNotFound(); var vm = EstablishmentViewModel.Parse(getOperation.Result); ViewData["Title"] = "Establishment"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "Details", Controller = "Establishments", Icon = "fa-search", Text = "Detail" }); ViewData["Region"] = RegionViewModel.Parse(getROperation.Result); ViewData["Company"] = CompanyViewModel.Parse(getCOperation.Result); ViewData["BreadCrumbs"] = crumbs; return View(vm); }
public IActionResult Details(int id) { try { var obj = _EstablishmentService.FindById(id); var status = _StatusService.FindAll(); var category = _CategoryService.ListCategory(); var address = _AddressService.FindById(obj.Id_Address); var city = _CityService.FindById(address.Id_City); ViewBag.Contacts = _ContactService.GroupFindById(id); var account = _AccountService.FindById(obj.idEstablishment); ViewBag.UF = _UFService.ListUF(); ViewBag.Message = TempData["info"]; EstablishmentViewModel ViewModel = new EstablishmentViewModel() { Establishment = obj, Status = status, Category = category, Address = address, City = city, Account = account }; return(View(ViewModel)); } catch (SqlException) { return(RedirectToAction("Error", "Home", new ErrorViewModel { Message = "Erro ao tentar conectar com o banco de dados" })); } catch { return(RedirectToAction("Error", "Home", new ErrorViewModel { Message = "Codigo de usuário inválido" })); } }
public ActionResult Create([FromBody] EstablishmentViewModel vm) { var e = new Establishment(vm.Address, vm.OpeningHours, vm.ClosingHours, vm.ClosingDays, vm.RegionId, vm.CompanyId); var res = _bo.Create(e); return(res.Success ? Ok() : InternalServerError()); }
public ActionResult Update([FromBody] EstablishmentViewModel establishment) { var currentRes = _bo.Read(establishment.Id); if (!currentRes.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } var current = currentRes.Result; if (current == null) { return(NotFound()); } if (current.Address == establishment.Address && current.ClosingDays == establishment.ClosingDays && current.ClosingHours == establishment.ClosingHours && current.OpeningHours == establishment.OpeningHours && current.RegionId == establishment.RegionId && current.CompanyId == establishment.CompanyId) { return(StatusCode((int)HttpStatusCode.NotModified)); } if (current.Address != establishment.Address) { current.Address = establishment.Address; } if (current.ClosingDays != establishment.ClosingDays) { current.ClosingDays = establishment.ClosingDays; } if (current.ClosingHours != establishment.ClosingHours) { current.ClosingHours = establishment.ClosingHours; } if (current.OpeningHours != establishment.OpeningHours) { current.OpeningHours = establishment.OpeningHours; } if (current.RegionId != establishment.RegionId) { current.RegionId = establishment.RegionId; } if (current.CompanyId != establishment.CompanyId) { current.CompanyId = establishment.CompanyId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok()); }
private async Task <List <EstablishmentViewModel> > GetEstablishmentViewModels(List <Guid> ids) { var filterOperation = await _ebo.FilterAsync(x => ids.Contains(x.Id)); var eList = new List <EstablishmentViewModel>(); foreach (var item in filterOperation.Result) { eList.Add(EstablishmentViewModel.Parse(item)); } return(eList); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListNotDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <ReservedQueueViewModel>(); foreach (var item in listOperation.Result) { var limitCheck = await _bo.TwoHourLimitReserveAsync(item.Id); if (limitCheck.Result && limitCheck.Success) { lst.Add(ReservedQueueViewModel.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 estList = await GetEstablishmentViewModels(listOperation.Result.Select(x => x.EstablishmentId).Distinct().ToList()); var profiList = await GetProfileViewModels(listOperation.Result.Select(x => x.ProfileId).Distinct().ToList()); var cList = await GetCompanyViewModels(listEOperation.Result.Select(x => x.CompanyId).Distinct().ToList()); ViewData["Companies"] = cList; ViewData["Establishments"] = estList; ViewData["Profiles"] = profiList; ViewData["Title"] = "Reserved Queues"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }
public async Task <JsonResult> NewEstablishment(EstablishmentViewModel model) { var user = HttpContext.Session.Get <User>(Constants.SessionKeyState); string userId = user.Id; model.userId = userId; var entity = model.ToEstablishmentModel(); var result = _establishmentAgent.CreateEstablishment(entity); user.Establishment = result.objectResult; HttpContext.Session.Set(Constants.SessionKeyState, user); return(await Task.FromResult(Json(result))); }
public IActionResult Update(EstablishmentViewModel obj) { if (obj.Establishment.CorporateName != null && (obj.Establishment.CNPJ != null && isCNPJAsync(obj.Establishment.CNPJ).Result == true) && obj.Establishment.Id_Category != 0 && obj.Address.Id_City != 0) { using (var transaction = _FitcardContext.Database.BeginTransaction()) { try { _AddressService.UpdateAddress(obj.Address); obj.Establishment.Id_Address = obj.Address.idAddress; if (_EstablishmentService.UpdateEstablishment(obj.Establishment)) { obj.Account.Id_Establishment = obj.Establishment.idEstablishment; if (!_AccountService.UpdateAccount(obj.Account)) { //agencia e conta não foram preenchidos corretamente, tendo só um dos campos sido preenchidos transaction.Rollback(); TempData["info"] = "É necessário informar conta e agência, um campo somente preenchido não é valido"; } else { transaction.Commit(); TempData["info"] = "Dados alterado com sucesso!"; } } else { //meio de contato não é valido para a categoria 1 transaction.Rollback(); TempData["info"] = "É necessário um meio de contato para a categoria de supermercado"; } } catch { transaction.Rollback(); return(RedirectToAction("Error", "Home", new ErrorViewModel { Message = "Erro ao tentar acessar e/ou atualizar dados no banco" })); } } } else { //campos obrigatorios não foram totalmente preenchidos TempData["info"] = "É necessário preencher todos os campos obrigatórios"; } return(RedirectToAction("Details", new { id = obj.Establishment.idEstablishment })); }
public ActionResult <List <EstablishmentViewModel> > List() { var res = _bo.List(); if (!res.Success) { return(InternalServerError()); } var list = new List <EstablishmentViewModel>(); foreach (var establishment in res.Result) { list.Add(EstablishmentViewModel.Parse(establishment)); } 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] EstablishmentViewModel vm) { var currentResult = _bo.Read(vm.Id); if (!currentResult.Success) { return(InternalServerError()); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Address == vm.Address && current.OpeningHours == vm.OpeningHours && current.ClosingHours == vm.ClosingHours && current.ClosingDays == vm.ClosingDays) { return(NotModified()); } if (current.Address != vm.Address) { current.Address = vm.Address; } if (current.OpeningHours != vm.OpeningHours) { current.OpeningHours = vm.OpeningHours; } if (current.ClosingHours != vm.ClosingHours) { current.ClosingHours = vm.ClosingHours; } if (current.ClosingDays != vm.ClosingDays) { current.ClosingDays = vm.ClosingDays; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(InternalServerError()); } return(Ok()); }
public ActionResult <EstablishmentViewModel> Get(Guid id) { var res = _bo.Read(id); if (res.Success) { if (res.Result == null) { return(NotFound()); } var vm = EstablishmentViewModel.Parse(res.Result); return(vm); } else { return(InternalServerError()); } }
public static Establishment ToEstablishmentModel(this EstablishmentViewModel viewModel) => new Establishment { id = viewModel.id, Name = viewModel.Name, Rfc = viewModel.Rfc, Email = viewModel.Email, PhoneNumber = viewModel.PhoneNumber, CostLevel = viewModel.CostLevel, Cover = viewModel.Cover, MusicalGenre = viewModel.MusicalGenre, Type = viewModel.Type, userId = viewModel.userId, Logo = ToLogoModel(viewModel.Logo), Address = ToAddressModel(viewModel.Address), FiscalAddress = ToAddressModel(viewModel.FiscalAddress), Inside = ToListImageModel(viewModel.Inside), Outside = ToListImageModel(viewModel.Outside) };
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 async Task<IActionResult> Create(EstablishmentViewModel vm) { if (ModelState.IsValid) { var model = vm.ToModel(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) return OperationErrorBackToIndex(createOperation.Exception); if (!createOperation.Result) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message); var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception); var cList = new List<SelectListItem>(); foreach (var item in listCOperation.Result) { cList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }); } var listROperation = await _rbo.ListNotDeletedAsync(); if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception); var rList = new List<SelectListItem>(); foreach (var item in listROperation.Result) { rList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }); } ViewBag.Regions = rList; ViewBag.Companies = cList; Draw("Create", "fa-plus"); return View(); } else return OperationSuccess("The record was successfuly created"); } return View(vm); }
private async Task <EstablishmentViewModel> GetEstablishmentViewModel(Guid id) { var getOperation = await _ebo.ReadAsync(id); return(EstablishmentViewModel.Parse(getOperation.Result)); }
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 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> Edit(Guid id, EstablishmentViewModel 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); getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) return OperationErrorBackToIndex(getOperation.Exception); if (getOperation.Result == null) return RecordNotFound(); var listROperation = await _rbo.ListNotDeletedAsync(); if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception); var rList = new List<SelectListItem>(); foreach (var item in listROperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.RegionId) listItem.Selected = true; rList.Add(listItem); } ViewBag.Regions = rList; var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception); var cList = new List<SelectListItem>(); foreach (var item in listCOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.CompanyId) listItem.Selected = true; cList.Add(listItem); } ViewBag.Companies = cList; vm = EstablishmentViewModel.Parse(getOperation.Result); Draw("Edit", "fa-edit"); return View(vm); } if (!updateOperation.Result) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message); getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) return OperationErrorBackToIndex(getOperation.Exception); if (getOperation.Result == null) return RecordNotFound(); var listROperation = await _rbo.ListNotDeletedAsync(); if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception); var rList = new List<SelectListItem>(); foreach (var item in listROperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.RegionId) listItem.Selected = true; rList.Add(listItem); } ViewBag.Regions = rList; var listCOperation = await _cbo.ListNotDeletedAsync(); if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception); var cList = new List<SelectListItem>(); foreach (var item in listCOperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name }; if (item.Id == vm.CompanyId) listItem.Selected = true; cList.Add(listItem); } ViewBag.Companies = cList; vm = EstablishmentViewModel.Parse(getOperation.Result); Draw("Edit", "fa-edit"); return View(vm); } else return OperationSuccess("The record was successfuly updated"); } } return RedirectToAction(nameof(Index)); }