コード例 #1
0
        public ActionResult CheckBookings()
        {
            List <BookingVM> bookList;

            try
            {
                var userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return(Error_FailedRequest());
                }

                bookList = BC.GetAllBookings("ACT", userId).ToList();
                if (bookList == null)
                {
                    return(Error_FailedRequest());
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            return(View(bookList));
        }
コード例 #2
0
        /// <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;
            }
        }
コード例 #3
0
        public ActionResult ChangePassword(string newPsw, string newPsw2, string oldPsw, string oldPsw2)
        {
            if (string.IsNullOrEmpty(newPsw) || string.IsNullOrEmpty(newPsw2) ||
                string.IsNullOrEmpty(oldPsw) || string.IsNullOrEmpty(oldPsw2))
            {
                return(Error_InvalidForm(false));
            }

            if (!oldPsw.Equals(oldPsw2) || !newPsw.Equals(newPsw2))
            {
                return(Error_CustomError("Las contraseñas ingresadas no coinciden", false));
            }

            try
            {
                var res = UC.UpdatePassword(newPsw, oldPsw);
                if (!res)
                {
                    return(Error_FailedRequest());
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message, false));
            }

            string successMsg = "Su contraseña fue cambiada";

            SetSuccessMsg(successMsg);

            return(RedirectToAction("Profile"));
        }
コード例 #4
0
        /// <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;
            }
        }
コード例 #5
0
        public ClaimsIdentity CreateIdentity(bool isAuthenticated, string userName, dynamic payload, string token)
        {
            if (string.IsNullOrEmpty(userName) || payload == null)
            {
                return(null);
            }

            try
            {
                // Decode the payload from token in order to create a claim
                string userId = payload.userId;
                string role   = payload.Usertype;

                // Define the claim
                var jwtIdentity = new ClaimsIdentity(
                    new JwtIdentity(isAuthenticated, userName, DefaultAuthenticationTypes.ApplicationCookie)
                    );

                // Add Claims NameIdentifier and Role
                jwtIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userId));
                jwtIdentity.AddClaim(new Claim(ClaimTypes.Role, role));
                jwtIdentity.AddClaim(new Claim(ClaimTypes.Authentication, token));

                return(jwtIdentity);
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(null);
            }
        }
コード例 #6
0
        /// <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;
            }
        }
コード例 #7
0
        /// <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;
            }
        }
コード例 #8
0
        public ActionResult CancelBook(string bookId)
        {
            if (string.IsNullOrEmpty(bookId))
            {
                return(Error_InvalidForm());
            }

            try
            {
                var res = BC.ChangeBookStatus(bookId, "CAN");
                if (!res)
                {
                    return(Error_FailedRequest());
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            string successMsg = "La Reserva fue cancelada";

            SetSuccessMsg(successMsg);

            string referer = GetRefererForError(Request);

            return(Redirect(referer));
        }
コード例 #9
0
        /// <summary>
        /// CREATES A FAKE IDENTITY FOR TESTING WITHOUT API
        /// </summary>
        public ClaimsIdentity CreateFakeIdentity()
        {
            try
            {
                // Decode the payload from token in order to create a claim
                string userId = "FAKE_USER_ID";
                string role   = "ADM";

                // Define the claim
                var jwtIdentity = new ClaimsIdentity(
                    new JwtIdentity(true, "FAKE_USER", DefaultAuthenticationTypes.ApplicationCookie)
                    );

                // Add Claims NameIdentifier and Role
                jwtIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userId));
                jwtIdentity.AddClaim(new Claim(ClaimTypes.Role, role));

                return(jwtIdentity);
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(null);
            }
        }
コード例 #10
0
        /// <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;
            }
        }
コード例 #11
0
        /// <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;
            }
        }
コード例 #12
0
        /// <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;
            }
        }
コード例 #13
0
        public ActionResult PayPub(string pubId)
        {
            if (string.IsNullOrEmpty(pubId))
            {
                return(Error_InvalidUrl());
            }

            PublicacionMec pub;

            try
            {
                pub = PC.GetPub(pubId);
                if (pub == null)
                {
                    return(Error_FailedRequest());
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            return(View(pub));
        }
コード例 #14
0
        public ActionResult PayPub(string pubId, bool res)
        {
            try
            {
                if (res)
                {
                    var changeRes = PC.ChangeStatus(pubId, "ACT");
                    if (!changeRes)
                    {
                        return(Error_FailedRequest());
                    }
                }
                else
                {
                    SetErrorMsg("Hubo un error procesando su pago, por favor inténtelo nuevamente. Si el problema persiste, contacte a soporte");
                    return(RedirectToAction("PubDetails", new { pubId }));
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            SetSuccessMsg("La Publicación fue pagada cone éxito");
            return(RedirectToAction("PubDetails", new { pubId }));
        }
コード例 #15
0
        public ActionResult AddPub(PublicacionMec newPub)
        {
            if (newPub == null)
            {
                return(Error_InvalidUrl());
            }

            string newPubId;

            try
            {
                newPub.created_at = DateTime.Now;
                newPub.updated_at = DateTime.Now;

                newPubId = PC.AddPub(newPub);
                if (newPubId == null)
                {
                    return(Error_FailedRequest());
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            SetSuccessMsg("Publicación creada con éxito, te vamos a mandar un mail cuando sea aceptada por nuestro personal!");
            return(RedirectToAction("PubDetails", new { pubId = newPubId }));
        }
コード例 #16
0
        public ActionResult PubList()
        {
            List <PublicacionMec> pubs;

            try
            {
                // Ger user data
                var userId = User.Identity.GetUserId();
                var user   = UC.GetUser(userId);
                if (user == null)
                {
                    return(Error_FailedRequest());
                }

                // Conseguir todas las publicaciones porque obvio no hay filtro de user por API :tired_af:
                pubs = PC.GetAllPub(string.Empty, string.Empty, string.Empty, string.Empty).ToList();
                if (pubs == null)
                {
                    return(Error_FailedRequest());
                }

                // Filtrar para las publicaciones de Mecánicos
                pubs = pubs.Where(x => x.appuser_id.Equals(userId)).ToList();
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            return(View(pubs));
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
        /// <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;
            }
        }
コード例 #19
0
        public ActionResult PubList(string comuna, string bussName, string pubTitle)
        {
            List <PublicacionMec> pubs;

            try
            {
                pubs = PMC.GetAllPub(comuna, "ACT", bussName, pubTitle).ToList();
                if (pubs == null)
                {
                    return(Error_FailedRequest());
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            // To keep the state of the search filters when the user make a search
            ViewBag.comuna   = comuna;
            ViewBag.bussName = bussName;
            ViewBag.pubTitle = pubTitle;

            return(View(pubs));
        }
コード例 #20
0
        /// <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;
            }
        }
コード例 #21
0
        /* ---------------------------------------------------------------- */
        /* SERVICES CALLER */
        /* ---------------------------------------------------------------- */

        /// <summary>
        /// API call to list all Services
        /// </summary>
        public IEnumerable <Servicio> GetAllServ(string name, string serv_status, bool deleted = false)
        {
            try
            {
                var delString = deleted ? "&deleted=true" : "";
                var url       = $"{fullPrefix}?name={name}&serv_status={serv_status}{delString}";

                // Request Base
                var request = new RestRequest(url, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                // Ejecutar request y guardar la respuesta
                var response = client.Execute <List <Servicio> >(request);

                // Levanta una excepción si el status code es diferente de 200
                CheckStatusCode(response);

                var servs = response.Data;

                // Retorna el producto
                return(servs);
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                throw e;
            }
        }
コード例 #22
0
        /// <summary>
        /// API call to list all Bookings
        /// </summary>
        public IEnumerable <BookingVM> GetAllBookings(string status_booking_id = "", string appuser_id = "", string serv_id = "", bool deleted = false)
        {
            try
            {
                var delString = deleted ? "&deleted=true" : "";
                var url       = $"{bookPrefix}?status_booking_id={status_booking_id}&serv_id={serv_id}&appuser_id={appuser_id}{delString}";

                // Request Base
                var request = new RestRequest(url, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                // Ejecutar request y guardar la respuesta
                var response = client.Execute <List <BookingVM> >(request);

                // Levanta una excepción si el status code es diferente de 200
                CheckStatusCode(response);

                var bookings = response.Data;

                // Data para conseguir la información más profunda de la venta
                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);
                }


                bookings.ForEach(book =>
                {
                    book = ProcessBook(book, bookStatusList, userList, servList);
                });

                // Retorna el producto
                return(bookings);
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                throw e;
            }
        }
コード例 #23
0
        public async Task <string> GetTokenAsync(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            // Encrypt the password using the key in Web.config
            password = EncryptHMAC(password);

            // Make the call to the API
            using (var client = new HttpClient())
            {
                try
                {
                    // Set the base address
                    client.BaseAddress = new Uri(_tokenUri);
                    // Set the Accept header value
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Define the content of the request
                    var content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("username", username),
                        new KeyValuePair <string, string>("hash", password),
                    });

                    // Call the API and save the response
                    var response = await client.PostAsync("/user-auth", content);

                    // Error handling by status code
                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        // If OK get the content (that is the token) and return it instead of the token
                        return(await response.Content.ReadAsStringAsync());
                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        // If Unauthorized get the error-code and return it instead of the token
                        var res = response.Headers.GetValues("error-code").First();
                        return(res);
                    }
                    else
                    {
                        // Return null if another thing happened
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    ErrorWriter.ExceptionError(e);
                    return(null);
                }
            }
        }
コード例 #24
0
        /// <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;
            }
        }
コード例 #25
0
        /* ---------------------------------------------------------------- */
        /* PRODUCTOS CALLER */
        /* ---------------------------------------------------------------- */

        /// <summary>
        /// API call to list all Products
        /// </summary>
        public IEnumerable <Producto> GetAllProd(string brand, string name, string product_status, bool deleted = false)
        {
            try
            {
                var delString = deleted ? "&deleted=true" : "";
                var url       = $"{fullPrefix}?brand={brand}&name={name}&product_status={product_status}{delString}";

                // Request Base
                var request = new RestRequest(url, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                // Ejecutar request y guardar la respuesta
                var response = client.Execute <List <Producto> >(request);

                // Levanta una excepción si el status code es diferente de 200
                CheckStatusCode(response);

                var prods = response.Data;

                var prodStatusLst = GetAllStatus().ToList();
                if (prodStatusLst == null)
                {
                    return(null);
                }

                var prodUnitLst = GetAllUnits().ToList();
                if (prodUnitLst == null)
                {
                    return(null);
                }

                prods.ForEach(pub =>
                {
                    pub = ProcessProd(pub, prodStatusLst, prodUnitLst);
                });

                // Retorna el producto
                return(prods);
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                throw e;
            }
        }
コード例 #26
0
        public ActionResult ServList()
        {
            List <UserServVM> servList = new List <UserServVM>();

            try
            {
                var userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return(Error_FailedRequest());
                }

                string n = string.Empty;

                var saleList = SC.GetAllSales(n, "PAG", id_appuser: userId);
                if (saleList == null)
                {
                    return(Error_FailedRequest());
                }

                foreach (var sale in saleList)
                {
                    sale.saleItems = SC.GetSaleItems(sale.sale_id).ToList();

                    foreach (var item in sale.saleItems)
                    {
                        if (item.serv != null)
                        {
                            var newServ = new UserServVM()
                            {
                                serv  = item.serv,
                                date  = sale.created_at,
                                total = item.total
                            };
                            servList.Add(newServ);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                return(Error_CustomError(e.Message));
            }

            return(View(servList));
        }
コード例 #27
0
        public ActionResult RescheduleBook(RescheduleBookVM model)
        {
            if (model == null)
            {
                return(Error_InvalidUrl());
            }
            var    newBook = model.booking;
            string bookId  = newBook.booking_id;

            try
            {
                var isAvailable = CheckBookAvailability(newBook);
                if (isAvailable == null)
                {
                    Error_FailedRequest();
                    return(RedirectToAction("CheckBookings", new { bookId }));
                }
                else if (isAvailable == false)
                {
                    SetErrorMsg("Ya hay una hora agendada para esa hora o hay conflicto con el horario de la tienda, por favor seleccione una diferente");
                    return(RedirectToAction("CheckBookings", new { bookId }));
                }

                Booking apiNewBook = newBook;

                var res = BC.UpdateBooking(apiNewBook);

                if (!res)
                {
                    Error_FailedRequest();
                    return(RedirectToAction("CheckBookings"));
                }
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                Error_CustomError(e.Message);
                return(RedirectToAction("CheckBookings"));
            }

            string successMsg = "La Reserva fue reagendada con éxito";

            SetSuccessMsg(successMsg);

            return(RedirectToAction("CheckBookings"));
        }
コード例 #28
0
        /* ---------------------------------------------------------------- */
        /* 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;
            }
        }
コード例 #29
0
        /// <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;
            }
        }
コード例 #30
0
        /// <summary>
        /// API call to list all Sales
        /// </summary>
        public IEnumerable <SaleVM> GetAllSales(string code, string sale_status_id, bool deleted = false, string id_cashier = "", string id_seller = "", string id_appuser = "")
        {
            try
            {
                var delString = deleted ? "&deleted=true" : "";
                var url       = $"{salesPrefix}?code={code}&id_cashier={id_cashier}&id_seller={id_seller}&id_appuser={id_appuser}&sale_status_id={sale_status_id}{delString}";

                // Request Base
                var request = new RestRequest(url, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                // Ejecutar request y guardar la respuesta
                var response = client.Execute <List <SaleVM> >(request);

                // Levanta una excepción si el status code es diferente de 200
                CheckStatusCode(response);

                var sales = response.Data;

                // Data para conseguir la información más profunda de la venta
                var saleStatusList = GetAllStatus().ToList();
                if (saleStatusList == null)
                {
                    return(null);
                }

                var userList = new UsuariosCaller().GetAllUsers(string.Empty, string.Empty, string.Empty, "ACT").ToList();

                sales.ForEach(sale =>
                {
                    sale = ProcessSale(sale, saleStatusList, userList);
                });

                // Retorna las ventas
                return(sales);
            }
            catch (Exception e)
            {
                ErrorWriter.ExceptionError(e);
                throw e;
            }
        }