public List<PurchaseRequisitionNoteModel> GetAllData()
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var data = _context.PurchaseRequisitionNotes.Select(a => new PurchaseRequisitionNoteModel()
                    {
                        PurchaseRequisitionNoteId = a.PurchaseRequisitionNoteId,
                        PrnNumber = a.PrnNumber,
                        CreatedBy = a.PrnNumber,
                        Reason = a.Reason,
                        IsApprovedByGM = a.IsApprovedByGM,
                        ApproverId = a.ApproverId,
                        DateOfApproved = a.DateOfApproved
                    }).ToList();
                    return data;
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
                throw;
            }
        }
        public int saveData(FinanceDispatchModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var addModel = new FinanceDispatch()
                    {
                        DispatchOrderId = model.DispatchOrderId,
                        EntryDate = model.EntryDate,
                        CreatedDate = model.CreatedDate,
                        CreatedBy = model.CreatedBy,

                    };
                    _context.Entry(addModel).State = EntityState.Added;
                    _context.SaveChanges();
                    model.FinanceDispatchId = addModel.FinanceDispatchId;

                    return model.FinanceDispatchId;
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                return 0;
            }
        }
        public int EditIssueMaterial(IssueMaterialModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var editModel = _context.IssueMaterials.FirstOrDefault(a => a.IssueProductMaterilId == model.IssueProductMaterilId);
                    if (editModel != null)
                    {
                        editModel.IssueProductMaterilId = model.IssueProductMaterilId;
                        editModel.Issuedcode = model.Issuedcode;
                        editModel.Issuedby = model.Issuedby;
                        editModel.BillOfMaterialId = model.BillOfMaterialId;
                        editModel.IssueRemarks = model.IssueRemarks;

                    }
                    _context.Entry(editModel).State = EntityState.Modified;
                    _context.SaveChanges();
                    return editModel.IssueProductMaterilId;
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
                throw;
            }
        }
        public bool EditData(MODEL.FinanceDispatchModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {

                    var data =
                        _context.FinanceDispatches.FirstOrDefault(a => a.FinanceDispatchId == model.FinanceDispatchId);

                        data.DispatchOrderId = model.DispatchOrderId;
                         data.EntryDate = model.EntryDate;
                         data.CreatedDate = model.CreatedDate;
                         data.CreatedBy = model.CreatedBy;

                    _context.Entry(data).State = EntityState.Modified;
                    _context.SaveChanges();

                    return true;
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                return false;
            }
        }
        public bool EditIssueproductionDetail(List<IssueMaterialDetailModel> modellist, int Issueproductionmaterialid)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    foreach (var issueproductiondetail in modellist)
                    {
                        var model = new IssueProductMaterialDetail()
                        {
                            IssueProductMaterialDetailId=issueproductiondetail.IssueProductMaterialDetailId,
                           IssueProductMaterialId = Issueproductionmaterialid,
                            ProductMaterialId = issueproductiondetail.ProductMaterialId,
                            OrderedQty = issueproductiondetail.OrderedQty,
                            ReturnQty = issueproductiondetail.ReturnQty,
                            IssuedQty = issueproductiondetail.IssuedQty,

                        };
                        _context.Entry(model).State = EntityState.Modified;
                        _context.SaveChanges();
                    }

                    return true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public GoodReceivedNoteModel GetAllDataBYId(int Joborderid)
        {
            try
            {
                using (_context= new HSSNInventoryEntities() )
                {
                    var data =
                        _context.GoodReceivedNotes.Where(a => a.JobOrderId == Joborderid)
                            .Select(a => new GoodReceivedNoteModel()
                            {
                                GoodReceivedNoteId = a.GoodReceivedNoteId,
                                GoodReceivedDate = a.GoodReceivedDate,
                                GoodRecievedBy = a.GoodReceivedBy,
                                CreatedBy = a.CreatedBy,
                                CreatedDate = a.CreatedDate,
                                ModifiedBy = a.ModifiedBy,
                                ModifiedDate = a.ModifiedDate,

                            }).FirstOrDefault();
                    return data;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new GoodReceivedNoteModel();

            }
        }
        public ProductModel GetProductDetailByProductId(int productId)
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {
                    var data = _context.Products.Where(b => b.ProductId == productId).Select(a => new ProductModel()
                    {
                        ProductId = a.ProductId,
                        BrandId = a.BrandId,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate,
                        ExerciseDuty = a.ExerciseDuty,
                        FlavourId = a.FlavourId,
                        IsVat = a.IsVat,
                        ModifiedBy = a.ModifiedBy,
                        ModifiedDate = a.ModifiedDate,
                        PacketPerCartoon = a.PacketPerCartoon
                    }).FirstOrDefault();
                    return data;
                }
                catch (Exception)
                {

                    return new ProductModel();
                }
            }
        }
 public ProductStockModel GetInfo(int ProductId, int OrganisationId, int WareHouseid)
 {
     try
     {
         using (_context = new HSSNInventoryEntities())
         {
             var data = (from a in _context.ProductStocks.ToList()
                         where
                             a.ProductId == ProductId && a.OrganisationId == OrganisationId &&
                             a.WareHouseId == WareHouseid
                         select new ProductStockModel()
                         {
                             ProductId = a.ProductId,
                             OrganisationId = a.OrganisationId,
                             WareHouseId = a.WareHouseId,
                         }).FirstOrDefault();
             if (data != null)
                 return data;
             else
                 return new ProductStockModel();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public List<ProductModel> GetdataByProductId(int Productid)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var data = (from a in _context.Products
                                join b in _context.DispatchOrderDetails on a.ProductId equals b.ProductId
                                join c in _context.DispatchOrders on b.DispatchOrderId equals c.DispatchOrderId
                                where a.ProductId==Productid
                                select new ProductModel()
                                {
                                    ProductId = a.ProductId,
                                    ProductName = a.ProductName,
                                    IsCheckedByManager = c.IsCheckedByManager,
                                    WhetherDoApproved = c.WhetherDoApproved,
                                    Quantity =b.Quantity,
                                    Rate=b.Rate,
                                }).ToList();
                    return data;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public MODEL.ProductionMaterialModel Save(MODEL.ProductionMaterialModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var addmodel = new ProductionMaterial()
                    {
                      MaterialName = model.MaterialName,
                      Description = model.Description,
                      MaterialType = model.MaterialType,
                      UnitOfMeasurementId = model.UnitOfMeasurementId

                    };
                    _context.Entry(addmodel).State = EntityState.Added;
                    _context.SaveChanges();
                    model.ProductionMaterialId = addmodel.ProductionMaterialId;
                    return model;
                }

            }
            catch (Exception aException)
            {
                return new ProductionMaterialModel();
            }
        }
        public List<ProductModel> GetAllProduct()
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {
                    var data = _context.Products.Select(a => new ProductModel()
                    {
                        ProductId = a.ProductId,
                        ProductName = a.ProductName,
                        BrandId = a.BrandId,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate,
                        ExerciseDuty = a.ExerciseDuty,
                        FlavourId = a.FlavourId,
                        IsVat = a.IsVat,
                        ModifiedBy = a.ModifiedBy,
                        ModifiedDate = a.ModifiedDate,
                        PacketPerCartoon = a.PacketPerCartoon
                    }).ToList();
                    return data;
                }
                catch (Exception)
                {

                    return new List<ProductModel>();
                }
            }
        }
        public List<BillOFMaterialModel> GetAllData()
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var data = _context.BillOfMaterials.Select(a => new BillOFMaterialModel()
                    {
                        BillOfMaterialId = a.BillOfMaterialId,
                        BillOfmaterialCode = a.BillOfmaterialCode,
                        ProductId = a.ProductId,
                        BatchQuantity = a.BatchQuantity,
                        CartoonQuantity = a.CartoonQuantity,
                        IsIssued = a.IsIssued,
                        PreparedBy = a.PreparedBy,
                        PreparedDate = a.PreparedDate,

                    }).ToList();
                    return data;
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
                throw;
            }
        }
        public List<MODEL.BillOfMaterialModel> GetAllNormTemplateByProductID(int productid, int batchquantity, int cartoonquantity)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var data = (from a in _context.Products
                                join b in _context.ProductNormTemplates on a.ProductId equals b.ProductId
                                join c in _context.ProductNormTemplateDetails on b.ProductNormTemplateId equals
                                    c.ProductNormTemplateId
                                join d in _context.ProductionMaterials on c.ProductionMaterialId equals d.ProductionMaterialId
                                join e in _context.SubProducts on c.SubProductId equals e.SubProductId
                                where a.ProductId == productid
                                select new BillOfMaterialModel()
                                {
                                    ProductMaterialId = d.ProductionMaterialId,
                                    ProductId = a.ProductId,
                                    SubProductId = e.SubProductId,
                                    subProductName = e.SubProductName,
                                    ProductMaterialName = d.MaterialName,
                                    BatchQuantity = c.BatchQuantity * batchquantity,
                                    CartoonQuantity = c.CartoonQuantity * cartoonquantity,

                                }).ToList();
                    return data;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public List<UserProfileModel> GetProfileData()
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var data =
                        _context.UserProfiles.Select(b => new UserProfileModel()
                            {
                                ProfileId = b.ProfileId,
                                ProfileName = b.ProfileName,
                                ProfileDesc = b.ProfileDesc,
                                CreatedDate = b.CreatedDate,
                                CreatedBy = b.CreatedBy

                            }).ToList();
                    return data;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                throw ex;
            }
        }
        public int editJobOrder(JobOrderModel model)
        {
            try
            {

                using (_context = new HSSNInventoryEntities())
                {
                    var editModel = _context.JobOrders.FirstOrDefault(a => a.JobOrderId == model.JobOrderId);
                    if (editModel != null)
                    {

                        //editModel.DealerId = model.DealerId;
                        //editModel.JobOrderDate = model.JobOrderDate;
                        //editModel.Description = model.Description;
                        //editModel.PreparedBy = model.PreparedBy;
                        editModel.IsApproved = model.IsApproved;
                        editModel.ApprovedBy = model.ApprovedBy;
                        //editModel.ModifiedDate = model.ModifiedDate;
                        //editModel.ApprovedDate = model.ApprovedDate;

                    }
                    _context.Entry(editModel).State = EntityState.Modified;
                    _context.SaveChanges();
                    return model.JobOrderId;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return 0;

            }
        }
        public int EditGoodReceivedNote(GoodReceivedNoteModel model)
        {
            try
            {

                using (_context= new HSSNInventoryEntities() )
                {
                    var editModel = _context.GoodReceivedNotes.FirstOrDefault(a => a.GoodReceivedNoteId == model.GoodReceivedNoteId);
                    if (editModel != null)
                    {

                        editModel.GoodReceivedBy = model.GoodRecievedBy;
                        editModel.GoodReceivedDate = model.GoodReceivedDate;
                        editModel.CreatedBy = model.CreatedBy;
                        editModel.CreatedDate = model.CreatedDate;

                    }
                    _context.Entry(editModel).State = EntityState.Modified;
                    _context.SaveChanges();
                    return model.GoodReceivedNoteId;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return 0;

            }
        }
        public List<ProductStockModel> GetAllProductDatabyWarehouseID(int warehouseid)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var data = (from a in _context.ProductStocks
                                join b in _context.Products on a.ProductId equals b.ProductId
                                where a.WareHouseId == warehouseid
                                select new ProductStockModel()
                                {
                                    ProductId = a.ProductId,
                                    ProductName = b.ProductName,
                                    CurrentStock = a.CurrentStock
                                }).ToList();
                    return data;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public Boolean EditPurchaseRequisitionNoteSumamry(PurchaseRequisitionNoteModel prnModel)
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {

                    var data =
                        _context.PurchaseRequisitionNotes.FirstOrDefault(
                            a => a.PurchaseRequisitionNoteId == prnModel.PurchaseRequisitionNoteId);

                    if (data != null)
                    {
                        data.PrnNumber = prnModel.PrnNumber;
                        data.CreatedBy = prnModel.PrnNumber;
                        data.Reason = prnModel.Reason;
                        data.IsApprovedByGM = prnModel.IsApprovedByGM;
                        data.ApproverId = prnModel.ApproverId;
                        data.DateOfApproved = prnModel.DateOfApproved;
                    }

                    _context.Entry(data).State = EntityState.Modified;
                    _context.SaveChanges();
                    //dispatchOrderModel.DispatchOrderId =data.DispatchOrderId;
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return false; //new DispatchOrderModel();
                }
            }
        }
        public bool SaveFinanceDispatchDetail(List<FinanceDispatchDetailModel> financeDispatchDetailModelsList, int FinanceDispatchid)
        {
            using (_context=new HSSNInventoryEntities())
            {
                try
                {
                    foreach (var rowData in financeDispatchDetailModelsList)
                    {
                        var model = new FinanceDispatchDetail()
                        {
                            FinanceDispatchId = FinanceDispatchid,
                            ProductId = rowData.ProductId,
                            DispatchFromWareHouseId = rowData.DispatchFromWareHouseId,
                            DispatchOrderId = rowData.DispatchOrderId,
                            Quantity = rowData.Quantity,
                            Rate = rowData.Rate,
                            ExcessShortageQuantity = rowData.ExcessShortageQuantity,
                            UnitOfMeasurementId = rowData.UnitOfMeasurementId,

                        };
                        _context.Entry(model).State=EntityState.Added;

                    }
                    _context.SaveChanges();
                    return true;
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }
        public List<FinanceDispatchDetailModel> GetAllFinanceDispatchDetailBydealerId(int dealerid,int WareHouseId)
        {
            try
               {
               using (_context= new HSSNInventoryEntities() )
               {
                   var data = (from a in _context.Dealers
                       join b in _context.DispatchOrders on a.DealerId equals b.DealerId
                       join c in _context.FinanceDispatchDetails on b.DispatchOrderId equals c.DispatchOrderId
                       join d in _context.Products on c.ProductId equals d.ProductId
                       join E in _context.FinanceDispatches on c.FinanceDispatchId equals E.FinanceDispatchId
                       where a.DealerId == dealerid && c.DispatchFromWareHouseId==WareHouseId
                       select new FinanceDispatchDetailModel()
                       {
                           FinanceDispatchId = E.FinanceDispatchId,
                           DispatchOrderId = b.DispatchOrderId,
                           ProductId = c.ProductId,
                           ProductName = d.ProductName,
                           DispatchFromWareHouseId = c.DispatchFromWareHouseId,
                           Quantity = c.Quantity,
                           ExcessShortageQuantity = c.ExcessShortageQuantity,
                           UnitOfMeasurementId = c.UnitOfMeasurementId,
                           Rate = c.Rate,

                       }).ToList();
                   return data;

               }
               }
               catch (Exception)
               {

               throw;
               }
        }
        public List<UserDetailModel> GetAllUserDetailData()
        {
            try
            {
                using (_context= new HSSNInventoryEntities() )
                {
                    var data = _context.UserDetails.Select(a => new UserDetailModel()
                    {
                        UserDetailId = a.UserDetailId,
                        Name = a.Name,
                        Address = a.Address,
                        Telephone = a.Telephone,
                        EmailId = a.EmailId,
                        UserName = a.UserName,
                        Password = a.Password,
                        DisplayName = a.DisplayName,
                        OrganisationId = a.OrganisationId,
                        CreatedDate = a.CreatedDate,
                        CreatedBy = a.CreatedBy,
                        ProfileId = a.ProfileId,
                    }).ToList();
                    return data;
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
                throw;
            }
        }
        public int EditUserDetail(UserDetailModel model)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var editModel = _context.UserDetails.FirstOrDefault(a => a.UserDetailId == model.UserDetailId);
                    if (editModel != null)
                    {

                        editModel.Name = model.Name;
                        editModel.Address = model.Address;
                        editModel.Telephone = model.Telephone;
                        editModel.EmailId = model.EmailId;
                        editModel.UserName = model.UserName;
                        editModel.Password = model.Password;
                        editModel.DisplayName = model.DisplayName;
                        editModel.OrganisationId = model.OrganisationId;
                        editModel.CreatedBy = model.CreatedBy;
                        editModel.CreatedDate = model.CreatedDate;
                        editModel.ProfileId = model.ProfileId;
                    }
                    _context.Entry(editModel).State = EntityState.Modified;
                    _context.SaveChanges();
                    return 1;
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
                throw;
            }
        }
        public void DeleteUserDetail(int UserDetailId)
        {
            using (_context= new HSSNInventoryEntities() )
            {
                var data = _context.UserDetails.FirstOrDefault(a => a.UserDetailId == UserDetailId);
                _context.Entry(data).State = EntityState.Deleted;
                _context.SaveChanges();

            }
        }
        public bool DeleteDetail(int JoborderID)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    _context.Database.ExecuteSqlCommand("DeleteJobOrderDetailByJobOrderId @joborderid",
                                            new SqlParameter("@joborderid", JoborderID));
                    return true;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public bool DeleteUserDetail(int ProfileId)
        {
            try
            {
                using (_context= new HSSNInventoryEntities() )
                {
                    _context.Database.ExecuteSqlCommand("DeleteUserDetailDataByProfileId @ProfileId",
                                              new SqlParameter("@ProfileId", ProfileId));
                    return true;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public bool DeleteGrnDetail(int GoodReceivedNoteId)
        {
            try
            {
                using (_context= new HSSNInventoryEntities() )
                {
                      _context.Database.ExecuteSqlCommand("DeleteGRNDetailByGoodReceivedNoteId @goodReceivedNoteId",
                                              new SqlParameter("@goodReceivedNoteId", GoodReceivedNoteId));
                    return true;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public bool Delete(int brandId)
        {
            try
            {
                using (_context = new HSSNInventoryEntities())
                {
                    var deleteModel = _context.Flavours.FirstOrDefault(a => a.FlavourId == brandId);
                    _context.Entry(deleteModel).State = EntityState.Deleted;
                    _context.SaveChanges();

                    return true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }
        }
Ejemplo n.º 28
0
        public Boolean Delete(int unitId)
        {
            try
            {
                using (_context= new HSSNInventoryEntities() )
                {
                    var data = _context.UnitOfMeasurements.FirstOrDefault(a => a.UnitOfMeasurementId == unitId);
                    _context.Entry(data).State = EntityState.Deleted;
                    _context.SaveChanges();
                    return true;
                }

            }

            catch (Exception e)
            {

                return false;
            }
        }
        public List<MODEL.BrandModel> GetAllBrands()
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {
                    var data = _context.Brands.Select(a => new BrandModel()
                    {
                       BrandId = a.BrandId,
                       BrandName = a.BrandName,
                       Description = a.Description
                    }).ToList();
                    return data;
                }
                catch (Exception)
                {

                    return new List<BrandModel>();
                }
            }
        }
        public List<MODEL.FlavourModel> GetAllFlavours()
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {
                    var data = _context.Flavours.Select(a => new FlavourModel()
                    {
                       FlavourId = a.FlavourId,
                       FlavourName = a.FlavourName,
                       Description = a.Description
                    }).ToList();
                    return data;
                }
                catch (Exception)
                {

                    return new List<FlavourModel>();
                }
            }
        }