Exemplo n.º 1
0
        public StockComment findByIdUserBeneficiaryAndLastComment(int idUserBeneficiary)
        {
            StockComment stockComment = (from sc in foodForAllContext.StockComment
                                         join s in foodForAllContext.Stock on sc.IdStock equals s.Id
                                         join p in foodForAllContext.Product on s.IdProduct equals p.Id
                                         join u in foodForAllContext.User on sc.IdUser equals u.Id
                                         where sc.IdUser == idUserBeneficiary
                                         select new StockComment()
            {
                IdTypeMessage = sc.IdTypeMessage,
                Comment = sc.Comment,
                Date = sc.Date,
                Id = sc.Id,
                IdStock = sc.IdStock,
                IdUser = sc.IdUser,
                IdUserNavigation = u,
                IdStockNavigation = new Stock()
                {
                    DateOfAdmission = s.DateOfAdmission,
                    ExpirationDate = s.ExpirationDate,
                    Id = s.Id,
                    IdProduct = s.IdProduct,
                    IdUser = s.IdUser,
                    IsAvailable = s.IsAvailable,
                    Observation = s.Observation,
                    Quantity = s.Quantity,
                    Status = s.Status,
                    UpdateDate = s.UpdateDate,
                    IdProductNavigation = p
                }
            }).OrderByDescending(sc => sc.Id).FirstOrDefault();

            return(stockComment);
        }
Exemplo n.º 2
0
        //Save a comment to the database
        public void SaveComment(String comment, String ticker)
        {
            Debug.WriteLine(comment + " " + ticker);

            String[] test = ticker.Split(' ');

            Debug.WriteLine(test[test.Length - 2]);

            //this grabs the ticker from the label.
            String tic = test[test.Length - 2];

            if (tic.Length < 5 && tic != "None")
            {
                using (CommentContext db = new CommentContext())
                {
                    StockComment com = new StockComment();
                    com.FBID    = (String)Session["FBID"];
                    com.Ticker  = tic;
                    com.Comment = comment;
                    Debug.WriteLine("WHAT");
                    if (db.StockComments.Find(com.FBID, com.Ticker) != null)
                    {
                        db.StockComments.Remove(db.StockComments.Find(com.FBID, com.Ticker));
                        db.StockComments.Add(com);
                        db.SaveChanges();
                    }
                    else
                    {
                        db.StockComments.Add(com);
                        db.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public StockComment create(StockComment stockComment)
        {
            stockComment.Date = DateTime.Now;

            foodForAllContext.StockComment.Add(stockComment);
            foodForAllContext.SaveChanges();

            return(stockComment);
        }
Exemplo n.º 4
0
        public StockComment destroyById(int id)
        {
            StockComment stockComment = (from sc in foodForAllContext.StockComment where sc.Id == id select sc).FirstOrDefault();

            foodForAllContext.StockComment.Remove(stockComment);
            foodForAllContext.SaveChanges();

            stockComment = findById(id);

            return(stockComment);
        }
Exemplo n.º 5
0
        public Stock getOneStock(String name)
        {
            //Currently hard coded from viewing a list of stocks
            String          url  = "http://download.finance.yahoo.com/d/quotes.csv?s=";
            HttpWebRequest  req  = (HttpWebRequest)WebRequest.Create(url + name + "&f=nsl1h0o");
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            StreamReader sr     = new StreamReader(resp.GetResponseStream());
            string       result = sr.ReadToEnd();

            sr.Close();

            Stock stock = new Stock();

            using (CommentContext db = new CommentContext())
            {
                StockComment com = db.StockComments.Find((String)Session["FBID"], name);
                if (com != null && com.Comment != null)
                {
                    stock.Comment = com.Comment;
                }
                else
                {
                    stock.Comment = "";
                }
            }

            if (!string.IsNullOrWhiteSpace(result))
            {
                String sn = result.Replace("\"", "").Replace(", ", " ");
                // Regex.Split(, "\r\n");
                string[] stockInfo = sn.Split(',');
                if (!sn.Contains("N/A") && stockInfo.Length > 4)
                {
                    stock.Ticker       = stockInfo[1];
                    stock.Name         = stockInfo[0];
                    stock.OpeningPrice = Convert.ToDouble(stockInfo[4]);
                    stock.CurrentPrice = Convert.ToDouble(stockInfo[2]);
                    stock.HighPrice    = Convert.ToDouble(stockInfo[3]);
                }
                else
                {
                    stock.Ticker       = "NA";
                    stock.Name         = "Not found";
                    stock.OpeningPrice = 0;
                    stock.CurrentPrice = 0;
                    stock.HighPrice    = 0;
                }
            }

            return(stock);
        }
Exemplo n.º 6
0
        public IActionResult findByIdUser([FromHeader(Name = "Authorization")] string token, int idUser)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new
                    {
                        message = "El Token es requerido.",
                        statusCode = HttpStatusCode.NoContent
                    }));
                }
                else
                {
                    string host          = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                    Token  tokenExisting = tokenService.findByToken(token, host);

                    if (tokenExisting != null)
                    {
                        User user = userService.findById(idUser);

                        if (user != null)
                        {
                            List <Chart> chartsDoughnut      = chartService.findByIdUserAndChartDoughnut(user.Id);
                            List <Chart> chartsDoughnutDonor = chartService.findByIdUserAndChartDoughnutDonor(user.Id);
                            List <Chart> chartsBar           = chartService.findByIdUserAndChartBar(user.Id);

                            User userDonorMaxStockRetirated = userService.findByIdUserBeneficiaryAndMaxStockRetirated(user.Id);

                            StockComment stockCommentLastBeneficiary = stockCommentService.findByIdUserBeneficiaryAndLastComment(user.Id);
                            StockComment stockCommentLastDonor       = stockCommentService.findByIdUserDonorAndLastComment(user.Id);

                            Product productLessReceived      = productService.findByIdUserBeneficiaryAndLessReceived(user.Id);
                            Product productMoreReceived      = productService.findByIdUserBeneficiaryAndMoreReceived(user.Id);
                            Product productLastReceived      = productService.findByIdUserBeneficiaryAndLastReceived(user.Id);
                            Product productLastStock         = productService.findByIdUserDonorAndLastStock(user.Id);
                            Product productLessQuantityStock = productService.findByIdUserDonorAndLessQuantityStock(user.Id);

                            EventLog eventLog = new EventLog();

                            eventLog.IdUser         = tokenExisting.IdUser;
                            eventLog.IdEventLogType = 1;
                            eventLog.Host           = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                            eventLog.HttpMethod     = ControllerContext.HttpContext.Request.Method;
                            eventLog.Controller     = ControllerContext.ActionDescriptor.ControllerName;
                            eventLog.Method         = ControllerContext.ActionDescriptor.ActionName;

                            eventLogService.create(eventLog);

                            return(Ok(new
                            {
                                user = user,
                                userDonorMaxStockRetirated = userDonorMaxStockRetirated,
                                chartsDoughnut = chartsDoughnut,
                                chartsDoughnutDonor = chartsDoughnutDonor,
                                chartsBar = chartsBar,
                                stockCommentLastBeneficiary = stockCommentLastBeneficiary,
                                stockCommentLastDonor = stockCommentLastDonor,
                                productLessReceived = productLessReceived,
                                productMoreReceived = productMoreReceived,
                                productLastReceived = productLastReceived,
                                productLastStock = productLastStock,
                                productLessQuantityStock = productLessQuantityStock,
                                statusCode = HttpStatusCode.OK
                            }));
                        }
                        else
                        {
                            return(Ok(new
                            {
                                message = "El Usuario no existe.",
                                statusCode = HttpStatusCode.NotFound
                            }));
                        }
                    }
                    else
                    {
                        return(Ok(new
                        {
                            message = "Token no permitido.",
                            statusCode = HttpStatusCode.Forbidden
                        }));
                    }
                }
            }
            catch (Exception exception)
            {
                EventLog eventLog = new EventLog();

                eventLog.IdEventLogType = 2;
                eventLog.Host           = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                eventLog.HttpMethod     = ControllerContext.HttpContext.Request.Method;
                eventLog.Controller     = ControllerContext.ActionDescriptor.ControllerName;
                eventLog.Method         = ControllerContext.ActionDescriptor.ActionName;
                eventLog.Message        = exception.InnerException != null ? exception.InnerException.Message : exception.Message;

                eventLogService.create(eventLog);

                return(Ok(new
                {
                    message = "Upps!!, tenemos un problema, intentalo nuevamente.",
                    statusCode = HttpStatusCode.InternalServerError
                }));
            }
        }
Exemplo n.º 7
0
        public StockComment findById(int id)
        {
            StockComment stockComment = (from sc in foodForAllContext.StockComment where sc.Id == id select sc).FirstOrDefault();

            return(stockComment);
        }
Exemplo n.º 8
0
        public IActionResult destroyById([FromHeader(Name = "Authorization")] string token, int id)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new
                    {
                        message = "El Token es requerido.",
                        statusCode = HttpStatusCode.NoContent
                    }));
                }
                else
                {
                    string host          = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                    Token  tokenExisting = tokenService.findByToken(token, host);

                    if (tokenExisting != null)
                    {
                        StockComment stockCommentExisting = stockCommentService.findById(id);

                        if (stockCommentExisting != null)
                        {
                            StockComment stockCommentDeleted = stockCommentService.destroyById(id);

                            if (stockCommentDeleted == null)
                            {
                                EventLog eventLog = new EventLog();

                                eventLog.IdUser         = tokenExisting.IdUser;
                                eventLog.IdEventLogType = 1;
                                eventLog.Host           = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                                eventLog.HttpMethod     = ControllerContext.HttpContext.Request.Method;
                                eventLog.Controller     = ControllerContext.ActionDescriptor.ControllerName;
                                eventLog.Method         = ControllerContext.ActionDescriptor.ActionName;

                                eventLogService.create(eventLog);

                                return(Ok(new
                                {
                                    message = "Comentario eliminado.",
                                    statusCode = HttpStatusCode.OK
                                }));
                            }
                            else
                            {
                                return(Ok(new
                                {
                                    message = "El comentario no se pudo eliminar, intentalo nuevamente.",
                                    statusCode = HttpStatusCode.NotFound
                                }));
                            }
                        }
                        else
                        {
                            return(Ok(new
                            {
                                message = "El comentario no existe.",
                                statusCode = HttpStatusCode.NotFound
                            }));
                        }
                    }
                    else
                    {
                        return(Ok(new
                        {
                            message = "Token no permitido.",
                            statusCode = HttpStatusCode.Forbidden
                        }));
                    }
                }
            }
            catch (Exception exception)
            {
                EventLog eventLog = new EventLog();

                eventLog.IdEventLogType = 2;
                eventLog.Host           = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                eventLog.HttpMethod     = ControllerContext.HttpContext.Request.Method;
                eventLog.Controller     = ControllerContext.ActionDescriptor.ControllerName;
                eventLog.Method         = ControllerContext.ActionDescriptor.ActionName;
                eventLog.Message        = exception.InnerException != null ? exception.InnerException.Message : exception.Message;

                eventLogService.create(eventLog);

                return(Ok(new
                {
                    message = "Upps!!, tenemos un problema, intentalo nuevamente.",
                    statusCode = HttpStatusCode.InternalServerError
                }));
            }
        }
Exemplo n.º 9
0
        public IActionResult create([FromHeader(Name = "Authorization")] string token, [FromBody] StockComment stockComment)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new
                    {
                        message = "El Token es requerido.",
                        statusCode = HttpStatusCode.NoContent
                    }));
                }
                else
                {
                    string host          = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                    Token  tokenExisting = tokenService.findByToken(token, host);

                    if (tokenExisting != null)
                    {
                        if (string.IsNullOrEmpty(stockComment.IdUser.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Usuario es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(stockComment.IdStock.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Stock es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(stockComment.IdTypeMessage.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Tipo de Mensaje es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(stockComment.Comment))
                        {
                            return(Ok(new
                            {
                                message = "El Comentario es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else
                        {
                            stockComment = stockCommentService.create(stockComment);

                            if (stockComment.Id != 0)
                            {
                                EventLog eventLog = new EventLog();

                                eventLog.IdUser         = tokenExisting.IdUser;
                                eventLog.IdEventLogType = 1;
                                eventLog.Host           = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                                eventLog.HttpMethod     = ControllerContext.HttpContext.Request.Method;
                                eventLog.Controller     = ControllerContext.ActionDescriptor.ControllerName;
                                eventLog.Method         = ControllerContext.ActionDescriptor.ActionName;

                                eventLogService.create(eventLog);

                                stockCommentHubContext.Clients.All.SendAsync("create", stockComment);

                                return(Ok(new
                                {
                                    message = "Comentario Agregado.",
                                    statusCode = HttpStatusCode.Created
                                }));
                            }
                            else
                            {
                                return(Ok(new
                                {
                                    message = "El Comentario no se pudo agregar, intentalo nuevamente.",
                                    statusCode = HttpStatusCode.NotFound
                                }));
                            }
                        }
                    }
                    else
                    {
                        return(Ok(new
                        {
                            message = "Token no permitido.",
                            statusCode = HttpStatusCode.Forbidden
                        }));
                    }
                }
            }
            catch (Exception exception)
            {
                EventLog eventLog = new EventLog();

                eventLog.IdEventLogType = 2;
                eventLog.Host           = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                eventLog.HttpMethod     = ControllerContext.HttpContext.Request.Method;
                eventLog.Controller     = ControllerContext.ActionDescriptor.ControllerName;
                eventLog.Method         = ControllerContext.ActionDescriptor.ActionName;
                eventLog.Message        = exception.InnerException != null ? exception.InnerException.Message : exception.Message;

                eventLogService.create(eventLog);

                return(Ok(new
                {
                    message = "Upps!!, tenemos un problema, intentalo nuevamente.",
                    statusCode = HttpStatusCode.InternalServerError
                }));
            }
        }