示例#1
0
        public bool Delete(string Id, ref string msg)
        {
            bool result = true;

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

            using (NuWebContext cxt = new NuWebContext())
            {
                try
                {
                    List <I_DataEntryDetail> listInsert = new List <I_DataEntryDetail>();
                    I_DataEntryDetail        item       = null;
                    foreach (var model in models)
                    {
                        item              = new I_DataEntryDetail();
                        item.Id           = Guid.NewGuid().ToString();
                        item.DataEntryId  = model.DataEntryId;
                        item.IngredientId = model.IngredientId;
                        //item.CloseBal = 0;//model.CloseBal;

                        listInsert.Add(item);
                    }

                    cxt.I_DataEntryDetail.AddRange(listInsert);
                    cxt.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                    result = false;
                }
                finally
                {
                    if (cxt != null)
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
示例#3
0
        public bool Insert(DataEntryModels model, bool isAutoCreate, ref string msg)
        {
            bool         result       = true;
            ResultModels resultModels = new ResultModels();

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        string dataEntryId = string.Empty;

                        I_DataEntry item = new I_DataEntry();

                        item.Id           = Guid.NewGuid().ToString();
                        dataEntryId       = item.Id;
                        item.EntryCode    = CommonHelper.GetGenNo(Commons.ETableZipCode.DataEntry, model.StoreId);
                        item.EntryDate    = model.EntryDate;
                        item.StoreId      = model.StoreId;
                        item.CreatedBy    = model.CreatedBy;
                        item.CreatedDate  = model.CreatedDate;
                        item.ModifierBy   = model.ModifierBy;
                        item.ModifierDate = model.ModifierDate;
                        item.IsActived    = model.IsActived;

                        //Detail
                        List <I_DataEntryDetail> listDetailInsert = new List <I_DataEntryDetail>();
                        I_DataEntryDetail        itemDetail       = null;

                        foreach (var detail in model.ListItem)
                        {
                            itemDetail              = new I_DataEntryDetail();
                            itemDetail.Id           = Guid.NewGuid().ToString();
                            itemDetail.DataEntryId  = item.Id;
                            itemDetail.IngredientId = detail.IngredientId;
                            itemDetail.Damage       = detail.Damage;
                            itemDetail.Wastage      = detail.Wast;
                            itemDetail.OrderQty     = detail.OrderQty;
                            itemDetail.Reasons      = detail.Reasons;

                            listDetailInsert.Add(itemDetail);
                        }

                        cxt.I_DataEntry.Add(item);
                        cxt.I_DataEntryDetail.AddRange(listDetailInsert);
                        cxt.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);
                        result = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        if (cxt != null)
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }
            return(result);
        }