Esempio n. 1
0
        public bool Delete(string Id, ref string msg)
        {
            bool result = true;

            using (NuWebContext cxt = new NuWebContext())
            {
                try
                {
                    I_Stock_Transfer_Detail itemDelete = (from tb in cxt.I_Stock_Transfer_Detail
                                                          where tb.Id == Id
                                                          select tb).FirstOrDefault();
                    //cxt.I_Stock_Transfer_Detail.Remove(itemDelete);
                    cxt.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                    result = false;
                }
                finally
                {
                    if (cxt != null)
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        public bool Insert(List <StockTransferDetailModels> models, ref string msg)
        {
            bool result = true;

            using (NuWebContext cxt = new NuWebContext())
            {
                try
                {
                    List <I_Stock_Transfer_Detail> listInsert = new List <I_Stock_Transfer_Detail>();
                    I_Stock_Transfer_Detail        item       = null;
                    foreach (var model in models)
                    {
                        item = new I_Stock_Transfer_Detail();

                        item.Id = Guid.NewGuid().ToString();
                        item.StockTransferId = model.StockTransferId;
                        item.IngredientId    = model.IngredientId;
                        item.RequestQty      = model.RequestQty;
                        item.ReceiveQty      = model.ReceiveQty;
                        item.IssueQty        = model.IssueQty;
                        item.UOMId           = model.UOMId;

                        listInsert.Add(item);
                    }

                    cxt.I_Stock_Transfer_Detail.AddRange(listInsert);
                    cxt.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                    result = false;
                }
                finally
                {
                    if (cxt != null)
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        public bool Insert(StockTransferModels model, ref string msg)
        {
            bool result = true;

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        ResultModels resultModels = new ResultModels();

                        I_Stock_Transfer item            = new I_Stock_Transfer();
                        string           StockTransferId = Guid.NewGuid().ToString();

                        item.Id = StockTransferId;
                        item.StockTransferNo = CommonHelper.GetGenNo(Commons.ETableZipCode.StockTransfer, model.IssueStoreId);

                        item.IssueStoreId   = model.IssueStoreId;
                        item.ReceiveStoreId = model.ReceiveStoreId;

                        item.RequestBy   = model.RequestBy;
                        item.RequestDate = model.RequestDate;

                        item.IssueBy   = model.IssueBy;
                        item.IssueDate = model.IssueDate;

                        item.ReceiveBy   = model.ReceiveBy;
                        item.ReceiveDate = model.ReceiveDate;

                        item.IsActive = model.IsActive;

                        List <I_Stock_Transfer_Detail> listInsert = new List <I_Stock_Transfer_Detail>();
                        I_Stock_Transfer_Detail        itemDetail = null;
                        //for stock
                        List <InventoryTransferModels> lstInventory = new List <InventoryTransferModels>();
                        InventoryTransferModels        inventory    = null;
                        foreach (var STDetailItem in model.ListItem)
                        {
                            itemDetail = new I_Stock_Transfer_Detail();

                            itemDetail.Id = Guid.NewGuid().ToString();
                            itemDetail.StockTransferId = StockTransferId;
                            itemDetail.IngredientId    = STDetailItem.IngredientId;
                            itemDetail.RequestQty      = STDetailItem.RequestQty;
                            itemDetail.ReceiveQty      = STDetailItem.ReceiveQty;
                            itemDetail.IssueQty        = STDetailItem.IssueQty;
                            itemDetail.UOMId           = STDetailItem.UOMId;
                            itemDetail.ReceiveBaseQty  = (STDetailItem.ReceiveQty * STDetailItem.Rate);
                            itemDetail.IssueBaseQty    = (STDetailItem.IssueQty * STDetailItem.Rate);

                            listInsert.Add(itemDetail);

                            inventory = new InventoryTransferModels();
                            inventory.IssueStoreId   = model.IssueStoreId;
                            inventory.ReceiveStoreId = model.ReceiveStoreId;
                            inventory.IngredientId   = STDetailItem.IngredientId;
                            inventory.IssueQty       = (STDetailItem.IssueQty * STDetailItem.Rate);
                            inventory.ReceiveQty     = (STDetailItem.ReceiveQty * STDetailItem.Rate);

                            inventory.Price = 0;

                            lstInventory.Add(inventory);
                        }

                        cxt.I_Stock_Transfer.Add(item);
                        cxt.I_Stock_Transfer_Detail.AddRange(listInsert);
                        cxt.SaveChanges();
                        transaction.Commit();

                        //Update inventory
                        _inventoryFactory.UpdateInventoryForTransfer(lstInventory, StockTransferId, ref resultModels);
                        _logger.Info(string.Format("UpdateInventoryForTransfer: [{0}] - [{1}] - [{2}] ", resultModels.IsOk, StockTransferId, resultModels.Message));
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);
                        result = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        if (cxt != null)
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }
            return(result);
        }