public StockReceived updateQuantityById(StockReceived stockReceived)
        {
            StockReceived stockReceivedExisting = (from sr in foodForAllContext.StockReceived where sr.Id == stockReceived.Id select sr).FirstOrDefault();

            stockReceivedExisting.Quantity = stockReceivedExisting.Quantity + stockReceived.Quantity;

            foodForAllContext.SaveChanges();

            Stock stock = (from s in foodForAllContext.Stock where s.Id == stockReceived.IdStock select s).FirstOrDefault();

            if (stock != null)
            {
                int quantity = stock.Quantity - stockReceived.Quantity;
                quantity = quantity < 0 ? 0 : quantity;

                stock.Quantity    = quantity;
                stock.IsAvailable = quantity == 0 ? false : true;
                stock.UpdateDate  = DateTime.Now;

                foodForAllContext.SaveChanges();

                if (!stock.IsAvailable)
                {
                    StockAvailable stockAvailable = (from sa in foodForAllContext.StockAvailable where sa.IdStock == stock.Id select sa).FirstOrDefault();
                    foodForAllContext.StockAvailable.Remove(stockAvailable);

                    foodForAllContext.SaveChanges();
                }
            }

            return(stockReceivedExisting);
        }
示例#2
0
        public XtraReportStockReceivedDetails(StockReceived stock, List <Product> stockDetails)
        {
            InitializeComponent();
            //monthCalendarAdv1.da
            // Select the week using SelectionStart and SelectionEnd.
            //this.monthCalendarAdv1.SelectionStart =
            //    new System.DateTime(stock.DateEstablish.Year, stock.DateEstablish.Month, stock.DateEstablish.Day - 1);
            //this.monthCalendarAdv1.SelectionEnd =
            //    new System.DateTime(stock.DateEstablish.Year, stock.DateEstablish.Month, stock.DateEstablish.Day + 6);

            XStockReceived temp = new XStockReceived()
            {
                ID      = stock.ID.ToString(), AdminName = stock.AdminName, UserAdmin = stock.AdminID,
                Deleted = stock.Deleted ? "Yes":"No", EstablishedDate = stock.DateEstablish
            };

            bindingSourceStockReceived.DataSource = temp;
            List <XProduct> result = new List <XProduct>();

            foreach (var i in stockDetails)
            {
                result.Add(new XProduct()
                {
                    Name  = i.Name, Type = i.Type?"Phone":"Other", Quantity = i.Quantity.ToString(), UnitPrice = i.UnitPrice, Description = i.Description,
                    Price = i.Price.ToString(),
                    Image = System.Drawing.Image.FromFile(@"images/" + i.Image)
                });
            }
            bindingSourceProducts.DataSource = result;
        }
        private void btnDetailsSave_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!isNew)
            {
                _managerStockedDetails.Delete(stockId);
            }
            else
            {
                var stock = new StockReceived {
                    AdminID = currMember.UseName, AdminInfo = currMember, DateEstablish = DateTime.Today, Deleted = false
                };
                stockId = _stockRepository.Add(stock);
            }
            for (int i = 0; i < cardViewStockDetails.DataRowCount; i++)
            {
                var temp = cardViewStockDetails.GetRow(i) as StockReceivedDetail;
                temp.StockRecievedID = stockId;
                _managerStockedDetails.Insert(temp).GetErrorMessages();
            }
            if (isNew)
            {
                xtraTabPage1.PageEnabled = true;
                isNew = false;

                btnAll.PerformClick();
            }
            expandablePanel.PerformClick();
            btnDetailsSave.Enabled = false;
        }
        public Product findByIdUserBeneficiaryAndLastReceived(int idUserBeneficiary)
        {
            Product product = null;

            StockReceived stockReceived = (from sr in foodForAllContext.StockReceived where sr.IdUserBeneficiary == idUserBeneficiary select sr).OrderByDescending(sr => sr.Id).FirstOrDefault();

            if (stockReceived != null)
            {
                Stock stock = stockService.findById(stockReceived.IdStock);

                product = stock != null?findById(stock.IdProduct) : null;
            }

            return(product);
        }
        public StockReceived findById(int id)
        {
            StockReceived stockReceived = (from sr in foodForAllContext.StockReceived
                                           join s in foodForAllContext.Stock on sr.IdStock equals s.Id
                                           join u in foodForAllContext.User on s.IdUser equals u.Id
                                           join p in foodForAllContext.Product on s.IdProduct equals p.Id
                                           join pt in foodForAllContext.ProductType on p.IdProductType equals pt.Id
                                           where sr.Id == id
                                           select new StockReceived()
            {
                IdStock = sr.IdStock,
                Date = sr.Date,
                Id = sr.Id,
                IdUserBeneficiary = sr.IdUserBeneficiary,
                Quantity = sr.Quantity,
                IdStockNavigation = new Stock()
                {
                    Id = s.Id,
                    DateOfAdmission = s.DateOfAdmission,
                    ExpirationDate = s.ExpirationDate,
                    IdProduct = s.IdProduct,
                    IdUser = s.IdUser,
                    IsAvailable = s.IsAvailable,
                    Observation = s.Observation,
                    Quantity = s.Quantity,
                    Status = s.Status,
                    UpdateDate = s.UpdateDate,
                    IdUserNavigation = u,
                    IdProductNavigation = new Product()
                    {
                        Description = p.Description,
                        Id = p.Id,
                        IdProductType = p.IdProductType,
                        Name = p.Name,
                        ReferenceImage = p.ReferenceImage,
                        Status = p.Status,
                        IdProductTypeNavigation = pt
                    }
                }
            }).FirstOrDefault();

            return(stockReceived);
        }
示例#6
0
        public IActionResult create([FromHeader(Name = "Authorization")] string token, [FromBody] StockReceived stockReceived)
        {
            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(stockReceived.IdStock.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Stock es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(stockReceived.IdUserBeneficiary.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Usuario Beneficiado es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(stockReceived.Quantity.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "La Cantidad es requerida.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else
                        {
                            stockReceived.Date = DateTime.Now;

                            StockReceived stockReceivedExisting = stockReceivedService.findByIdUserBeneficiaryAndIdStockAndDate(stockReceived.IdUserBeneficiary, stockReceived.IdStock, stockReceived.Date);

                            if (stockReceivedExisting != null)
                            {
                                stockReceived.Id = stockReceivedExisting.Id;

                                StockReceived stockReceivedUpdated = stockReceivedService.updateQuantityById(stockReceived);

                                if (stockReceivedUpdated != 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);

                                    stockReceivedUpdated = stockReceivedService.findById(stockReceivedUpdated.Id);

                                    stockReceivedContext.Clients.All.SendAsync("create", stockReceivedUpdated);

                                    return(Ok(new
                                    {
                                        message = "Stock Recibido Actualizado.",
                                        statusCode = HttpStatusCode.OK
                                    }));
                                }
                                else
                                {
                                    return(Ok(new
                                    {
                                        message = "El Stock Recibido no se pudo actualizar, intentalo nuevamente.",
                                        statusCode = HttpStatusCode.NotFound
                                    }));
                                }
                            }
                            else
                            {
                                stockReceived = stockReceivedService.create(stockReceived);

                                if (stockReceived.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);

                                    stockReceived = stockReceivedService.findById(stockReceived.Id);

                                    stockReceivedContext.Clients.All.SendAsync("create", stockReceived);

                                    return(Ok(new
                                    {
                                        message = "Stock Recibido Agregado.",
                                        statusCode = HttpStatusCode.Created
                                    }));
                                }
                                else
                                {
                                    return(Ok(new
                                    {
                                        message = "El Stock Recibido 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
                }));
            }
        }
        public StockReceived findByIdUserBeneficiaryAndIdStockAndDate(int idUserBeneficiary, int idStock, DateTime date)
        {
            StockReceived stockReceived = (from sr in foodForAllContext.StockReceived where sr.IdUserBeneficiary == idUserBeneficiary && sr.IdStock == idStock && sr.Date == date select sr).FirstOrDefault();

            return(stockReceived);
        }