public ActionResult Export([Bind("searchValue,searchOld")] VMSearchClient payload) { List <Client> list; if (string.IsNullOrEmpty(payload.searchOld) || string.IsNullOrWhiteSpace(payload.searchOld)) { list = _clientService.GetAll(); } else { list = _clientService.GetClientByNameOrRGOrCPF(payload.searchOld); } DataTable dt = GetDataTable(list); if (dt.Rows.Count == 0) { var mMessages = new VMMessages() { Css = "msg-sucesso", Text = "Não há itens para serem exportados!" }; TempData["_mensagem"] = JsonConvert.SerializeObject(mMessages); return(RedirectToAction("Index")); } Excel excel = new Excel(); return(excel.ExportData("Clientes", dt)); }
public ActionResult Edit(int?id) { if (id == null) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; return(RedirectToAction(nameof(Index))); } var client = _clientService.findById(id.Value); if (client == null) { var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); return(RedirectToAction(nameof(Index))); } ViewData["idCity"] = new SelectList(_cityService.GetCitiesByState(client.idState), "Id", "Name", client.idCity); ViewData["idPlanType"] = new SelectList(_planTypeService.GetAll(), "Id", "Name", client.idPlanType); ViewData["idState"] = new SelectList(_stateService.GetAll(), "Id", "Name", client.idState); ViewData["idTypePayment"] = new SelectList(_typePaymentService.GetAll(), "Id", "Name", client.idTypePayment); return(View(_mapper.Map <VMClient>(client))); }
public ActionResult Edit(int?id) { if (id == null) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; return(RedirectToAction(nameof(Index))); } var entity = _instructorService.findById(id.Value); if (entity == null) { var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); return(RedirectToAction(nameof(Index))); } ViewData["idCity"] = new SelectList(_cityService.GetCitiesByState(entity.idState), "Id", "Name", entity.idCity); ViewData["idState"] = new SelectList(_stateService.GetAll(), "Id", "Name", entity.idState); return(View(_mapper.Map <VMInstructor>(entity))); }
public ActionResult Create([Bind("Name,Email,Password,RG,cpf,Street,Neighborhood,idCity,idState,ContractStartDate,idPlanType,idTypePayment,idUser")] VMClient payload) { try { if (!ModelState.IsValid) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Não foi possivel realizar seu cadastro,tente novamente!" }; //return BadRequest(ModelState.GetErrorMessages()); ViewData["idCity"] = new SelectList(_cityService.GetCitiesByState(payload.idState), "Id", "Name", payload.idCity); ViewData["idPlanType"] = new SelectList(_planTypeService.GetAll(), "Id", "Name"); ViewData["idState"] = new SelectList(_stateService.GetAll(), "Id", "Name"); ViewData["idTypePayment"] = new SelectList(_typePaymentService.GetAll(), "Id", "Name"); return(View(payload)); } var result = _clientService.Save(payload); var _msg = new VMMessages() { Css = "alert alert-success", Text = "Cadastro salvo com sucesso!" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); return(RedirectToAction(nameof(Index))); } catch (CustomHttpException ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = ex.ErrorMessage }; } catch (Exception ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; } ViewData["idCity"] = new SelectList(_cityService.GetCitiesByState(payload.idState), "Id", "Name", payload.idCity); ViewData["idPlanType"] = new SelectList(_planTypeService.GetAll(), "Id", "Name"); ViewData["idState"] = new SelectList(_stateService.GetAll(), "Id", "Name"); ViewData["idTypePayment"] = new SelectList(_typePaymentService.GetAll(), "Id", "Name"); return(View(payload)); }
public ActionResult ReciverMessages() { if (!Authorize()) { return(RedirectToAction("RedirectByUser", "Home")); } VMMessages msgs = new VMMessages(); MessageDal msDal = new MessageDal(); User curr = (User)Session["CurrentUser"]; msgs.Messages = (from msg in msDal.messages where msg.Receiver == curr.UserName select msg).ToList <Message>(); return(View(msgs)); }
public ActionResult DeleteConfirmed(int id) { try { var payload = _clientService.findById(id); if (payload == null) { return(NotFound()); } if (_clientService.Remove(payload)) { var mMessages = new VMMessages() { Css = "alert alert-success", Text = "Cliente removido com sucesso!" }; TempData["_mensagem"] = JsonConvert.SerializeObject(mMessages); } else { var mMessages = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(mMessages); } return(RedirectToAction(nameof(Index))); } catch (CustomHttpException ex) { //return StatusCode(ex.StatusCode, ex.ErrorMessage); } catch (Exception ex) { _logger.Log(LogLevel.Error, ex.Message); //return StatusCode(500, new { error = "Internal server error" }); } var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Index([Bind("Email,Password")] VMLoginRequest payload) { try { if (ModelState.IsValid) { User user = _authService.CreateAccessToken(this.HttpContext, payload.Email, payload.Password); var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()), new Claim(ClaimTypes.Role, user.UserType.Name) }, CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity); var authProperties = new AuthenticationProperties { }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); var url = Url.Content("~/Home"); return(Redirect(url)); } } catch (CustomHttpException ex) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = ex.ErrorMessage }; } catch (Exception ex) { // TODO: Log ex TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = ex.Message }; } return(View(payload)); }
public ActionResult Index([Bind("searchValue,searchOld,initDateOld,initDate,finalDateOld,finalDate")] VMSearchpayment payload) { if (payload.finalDate == null) { payload.finalDate = DateTime.Now; } if (payload.initDate == null) { payload.initDate = DateTime.MinValue; } try { if (string.IsNullOrEmpty(payload.searchValue) || string.IsNullOrWhiteSpace(payload.searchValue)) { return(View(_paymentService.GetPaymentsThatAreNotPaidAndNeeded(payload.initDate.Value, payload.finalDate.Value))); } else { ViewData["searchOld"] = payload.searchValue; ViewData["finalDateOld"] = payload.finalDate; ViewData["initDateOld"] = payload.initDateOld; return(View(_paymentService.GetPaymentsByNameOrRGOrCPF(payload.searchValue, payload.initDate.Value, payload.finalDate.Value))); } } catch (CustomHttpException ex) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; } catch (Exception ex) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; } return(View(_paymentService.GetPaymentsThatAreNotPaidAndNeeded(payload.initDate.Value, payload.finalDate.Value))); }
public ActionResult Export([Bind("searchValue,searchOld,initDateOld,initDate,finalDateOld,finalDate")] VMSearchpayment payload) { if (payload.finalDateOld == null) { payload.finalDateOld = DateTime.Now; } if (payload.initDateOld == null) { payload.initDateOld = DateTime.MinValue; } List <Payment> list; if (string.IsNullOrEmpty(payload.searchOld) || string.IsNullOrWhiteSpace(payload.searchOld)) { list = _paymentService.GetPaymentsThatAreNotPaidAndNeeded(payload.initDateOld.Value, payload.finalDateOld.Value); } else { list = _paymentService.GetPaymentsByNameOrRGOrCPF(payload.searchOld, payload.initDateOld.Value, payload.finalDateOld.Value); } DataTable dt = GetDataTable(list); if (dt.Rows.Count == 0) { var mMessages = new VMMessages() { Css = "msg-sucesso", Text = "Não há itens para serem exportados!" }; TempData["_mensagem"] = JsonConvert.SerializeObject(mMessages); return(RedirectToAction("Index")); } Excel excel = new Excel(); return(excel.ExportData("Lista de Inadimplentes", dt)); }
//[Authorize(Roles = "Recepcionista")] public ActionResult Index([Bind("searchValue,searchOld")] VMSearchClient payload) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } if (string.IsNullOrEmpty(payload.searchValue) || string.IsNullOrWhiteSpace(payload.searchValue)) { return(View(_clientService.GetAll())); } else { ViewData["searchOld"] = payload.searchValue; return(View(_clientService.GetClientByNameOrRGOrCPF(payload.searchValue))); } } catch (CustomHttpException ex) { TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = ex.ErrorMessage }; } catch (Exception ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; } return(View(_clientService.GetAll())); }
public ActionResult Edit(int id, [Bind("IdRegistration,Name,Email,Password,RG,cpf,Street,Neighborhood,idCity,idState,ContractStartDate,ContractEndDate,idPlanType,idTypePayment,idUser,CreatedAt,UpdatedAt,DeletedAt")] VMClient payload) { try { if (id != payload.IdRegistration) { var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro inseperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { var result = _clientService.Update(payload); if (result) { var _msg = new VMMessages() { Css = "alert alert-success", Text = "Editado com sucesso!" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); } else { var _msg = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; TempData["_mensagem"] = JsonConvert.SerializeObject(_msg); } return(RedirectToAction(nameof(Index))); } } catch (CustomHttpException ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = ex.ErrorMessage }; } catch (Exception ex) { _logger.Log(LogLevel.Error, ex.Message); TempData["_mensagem"] = new VMMessages() { Css = "alert alert-danger", Text = "Um erro insperado ocorreu" }; } ViewData["idCity"] = new SelectList(_cityService.GetCitiesByState(payload.idState), "Id", "Name", payload.idCity); ViewData["idPlanType"] = new SelectList(_planTypeService.GetAll(), "Id", "Name", payload.idPlanType); ViewData["idState"] = new SelectList(_stateService.GetAll(), "Id", "Name", payload.idState); ViewData["idTypePayment"] = new SelectList(_typePaymentService.GetAll(), "Id", "Name", payload.idTypePayment); return(View(payload)); }