/// <summary> /// API call to get a Mechanic /// </summary> /// <param name="mechId"> Mechanic Id </param> public Mecanico GetMech(string mechId) { if (string.IsNullOrEmpty(mechId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{prefix}/mechanics/{mechId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <Mecanico>(request); string notFoundMsg = "El Mecánico requerido no existe"; CheckStatusCode(response, notFoundMsg); return(response.Data); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to change the Status of a Mechanic /// </summary> /// <param name="mechId"> User Id </param> /// <param name="statusId"> User Status Id </param> public bool ChangeMechStatus(string mechId, string statusId) { if (string.IsNullOrEmpty(mechId) || string.IsNullOrEmpty(statusId)) { ErrorWriter.InvalidArgumentsError(); return(false); } try { string url = $"{prefix}/mechanics/{mechId}/change-status?status={statusId}"; var request = new RestRequest(url, Method.POST); var response = client.Execute(request); // Throw an exception if the StatusCode is different from 200 CheckStatusCode(response); return(true); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to get an User /// </summary> /// <param name="userId"> User Id </param> public Usuario GetUser(string userId) { if (string.IsNullOrEmpty(userId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{prefix}/users/{userId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <Usuario>(request); string notFoundMsg = "El Usuario requerido no existe"; CheckStatusCode(response, notFoundMsg); return(response.Data); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// Returns the HTML of the modal to reschedule a Booking for an specific Booking /// </summary> /// <param name="bookId">Id of the Booking to Reschedule</param> public string GetRescheduleBookModalHtml(string bookId) { if (string.IsNullOrEmpty(bookId)) { ErrorWriter.InvalidArgumentsError(); return(Resources.Messages.Error_SolicitudFallida); } string html; try { var model = new RescheduleBookVM(); var booking = BC.GetBook(bookId); model.booking = booking; var otherBookList = BC.GetAllBookings("ACT", serv_id: booking.serv_id).ToList(); model.otherBookList = otherBookList.Where(x => x.start_date_hour > DateTime.Now).ToList(); var restList = BC.GetAllBookRest(booking.serv_id).ToList(); model.restList = restList.Where(x => x.start_date_hour > DateTime.Now).ToList(); html = PartialView("Partial/_rescheduleBookModal", model).RenderToString(); } catch (Exception e) { ErrorWriter.ExceptionError(e); return(Resources.Messages.Error_SolicitudFallida); } return(html); }
/// <summary> /// API call to change the Status of a Booking /// </summary> /// <param name="bookId"> Booking Id </param> /// <param name="bookStatusId"> Booking Status Id </param> public bool ChangeBookStatus(string bookId, string bookStatusId) { if (string.IsNullOrEmpty(bookId) || string.IsNullOrEmpty(bookStatusId)) { ErrorWriter.InvalidArgumentsError(); return(false); } try { var request = new RestRequest($"{bookPrefix}/{bookId}/change-status?status={bookStatusId}", Method.POST); var response = client.Execute(request); // Throw an exception if the StatusCode is different from 200 CheckStatusCode(response); return(true); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to add a Booking /// </summary> /// <param name="newRest"> New Booking </param> public string AddBooking(Booking newBook) { if (newBook == null) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{bookPrefix}", Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(newBook); var response = client.Execute(request); CheckStatusCode(response); return(response.Content); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to update a Booking /// </summary> /// <param name="newBook"> New Booking </param> public bool UpdateBooking(Booking newBook) { if (newBook == null) { ErrorWriter.InvalidArgumentsError(); return(false); } try { newBook.updated_at = DateTime.Now; var bookId = newBook.booking_id; var request = new RestRequest($"{bookPrefix}/{bookId}", Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(newBook); var response = client.Execute(request); string notFoundMsg = "La Reserva requerida no existe"; CheckStatusCode(response, notFoundMsg); return(true); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to change the Password of an User /// </summary> /// <param name="password"></param> /// <param name="oldPassword"></param> /// <returns></returns> public bool UpdatePassword(string password, string oldPassword) { if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(oldPassword)) { ErrorWriter.InvalidArgumentsError(); return(false); } try { var request = new RestRequest($"user-auth/change-password", Method.POST); password = JwtProvider.EncryptHMAC(password); oldPassword = JwtProvider.EncryptHMAC(oldPassword); request.AddJsonBody(new { psw = password, old_psw = oldPassword }); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.Conflict) { throw new Exception("La contraseña ingresada es incorrecta"); } // Throw an exception if the StatusCode is different from 200 CheckStatusCode(response); return(true); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to update an User /// </summary> /// <param name="newUser"> New User </param> public bool UpdateUser(Usuario newUser) { if (newUser == null) { ErrorWriter.InvalidArgumentsError(); return(false); } try { var userId = newUser.appuser_id; var request = new RestRequest($"{prefix}/users/{userId}", Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(newUser); var response = client.Execute(request); string notFoundMsg = "El Usuario requerido no existe"; CheckStatusCode(response, notFoundMsg); return(true); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to get a Service /// </summary> /// <param name="servId"> Service Id </param> public Servicio GetServ(string servId) { if (string.IsNullOrEmpty(servId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{fullPrefix}/{servId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <Servicio>(request); string notFoundMsg = "El Servicio requerido no existe"; CheckStatusCode(response, notFoundMsg); var serv = response.Data; return(serv); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to get a Booking /// </summary> /// <param name="bookId"> Booking Id </param> public BookingVM GetBook(string bookId) { if (string.IsNullOrEmpty(bookId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{bookPrefix}/{bookId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <BookingVM>(request); string notFoundMsg = "La Reserva requerida no existe"; CheckStatusCode(response, notFoundMsg); var book = response.Data; var bookStatusList = GetAllBookStatus().ToList(); if (bookStatusList == null) { return(null); } var userList = new UsuariosCaller().GetAllUsers(string.Empty, string.Empty, string.Empty, "ACT").ToList(); if (userList == null) { return(null); } var servList = new ServCaller().GetAllServ(string.Empty, "ACT").ToList(); if (servList == null) { return(null); } book = ProcessBook(book, bookStatusList, userList, servList); return(book); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/* ---------------------------------------------------------------- */ /* SALE ITEM */ /* ---------------------------------------------------------------- */ /// <summary> /// API call to list all Sale Items of a Sale /// </summary> public IEnumerable <SaleItemVM> GetSaleItems(string saleId) { if (string.IsNullOrEmpty(saleId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{prefix}/provisions/{saleId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <List <SaleItemVM> >(request); string notFoundMsg = "Items de la venta no encontrados"; CheckStatusCode(response, notFoundMsg); var saleItems = response.Data; var prodList = new ProductosCaller().GetAllProd(string.Empty, string.Empty, string.Empty).ToList(); var delProdList = new ProductosCaller().GetAllProd(string.Empty, string.Empty, string.Empty, true).ToList(); prodList.AddRange(delProdList); var servList = new ServCaller().GetAllServ(string.Empty, string.Empty).ToList(); var delServList = new ServCaller().GetAllServ(string.Empty, string.Empty, true).ToList(); servList.AddRange(delServList); saleItems.ForEach(x => { x = ProcessSaleItem(x, prodList, servList); }); return(saleItems); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to get a Sale /// </summary> /// <param name="saleId"> Sale Id </param> public SaleVM GetSale(string saleId) { if (string.IsNullOrEmpty(saleId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{salesPrefix}/{saleId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <SaleVM>(request); string notFoundMsg = "La venta requerida no existe"; CheckStatusCode(response, notFoundMsg); var sale = response.Data; var saleStatusList = GetAllStatus().ToList(); if (saleStatusList == null) { return(null); } var userList = new UsuariosCaller().GetAllUsers(string.Empty, string.Empty, string.Empty, "ACT").ToList(); sale = ProcessSale(sale, saleStatusList, userList); // Agregar los Items de la venta ya que es el detalle var saleItems = GetSaleItems(sale.sale_id); sale.saleItems = saleItems.ToList(); return(sale); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to get a Product /// </summary> /// <param name="prodId"> Product Id </param> public Producto GetProd(string prodId) { if (string.IsNullOrEmpty(prodId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{fullPrefix}/{prodId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <Producto>(request); string notFoundMsg = "El Producto requerido no existe"; CheckStatusCode(response, notFoundMsg); var prod = response.Data; var prodStatusLst = GetAllStatus().ToList(); if (prodStatusLst == null) { return(null); } var prodUnitLst = GetAllUnits().ToList(); if (prodUnitLst == null) { return(null); } prod = ProcessProd(prod, prodStatusLst, prodUnitLst); return(prod); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call to get a Booking Restriction /// </summary> /// <param name="restId"> Restriction Id </param> public BookingRestVM GetBookRest(string restId) { if (string.IsNullOrEmpty(restId)) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var request = new RestRequest($"{restPrefix}/{restId}", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute <BookingRestVM>(request); string notFoundMsg = "La Reserva requerida no existe"; CheckStatusCode(response, notFoundMsg); var rest = response.Data; var servList = new ServCaller().GetAllServ(string.Empty, "ACT").ToList(); if (servList == null) { return(null); } rest = ProcessRest(rest, servList); return(rest); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// API call that will send an Email to the User with a new password. It doesn't matter if the mail exist or not, /// the request will always return 200 if the connection was successful /// </summary> /// <param name="email"> User Email </param> public bool ResetPassword(string email) { if (string.IsNullOrEmpty(email)) { ErrorWriter.InvalidArgumentsError(); return(false); } try { var request = new RestRequest($"user-auth/Recover-pass?email={email}", Method.POST); var response = client.Execute(request); return(true); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/* ---------------------------------------------------------------- */ /* USER AUTH */ /* ---------------------------------------------------------------- */ /// <summary> /// API call to register an User /// </summary> /// <param name="newUser"> New User </param> public string RegisterUser(Usuario newUser) { if (newUser == null) { ErrorWriter.InvalidArgumentsError(); return(null); } try { var userId = newUser.appuser_id; var request = new RestRequest("user-auth/register", Method.POST) { RequestFormat = DataFormat.Json }; newUser.hash = JwtProvider.EncryptHMAC(newUser.hash); request.AddJsonBody(newUser); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.Conflict) { throw new Exception("El Nombre de Usuario o Mail ya existe"); } CheckStatusCode(response); return(response.Content); } catch (Exception e) { ErrorWriter.ExceptionError(e); throw e; } }
/// <summary> /// Return the HTML of the receipt of a Booking. Is expected to be put inside a <iframe> /// </summary> /// <param name="bookId">Id of the Booking</param> public string GetBookingReceipt(string bookId) { if (string.IsNullOrEmpty(bookId)) { ErrorWriter.InvalidArgumentsError(); return(Resources.Messages.Error_SolicitudFallida); } string html; try { var item = BC.GetBook(bookId); html = PartialView("Partial/_bookingReceipt", item).RenderToString(); } catch (Exception e) { ErrorWriter.ExceptionError(e); return(Resources.Messages.Error_SolicitudFallida); } return(html); }