public ResponseModel CreatePackageDetails(PackageDetailsViewModel packageData, List <ProductPackageVM> productList)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime aDate = DateTime.Now;

                    InvPackageMaster aPackageMaster = new InvPackageMaster()
                    {
                        PackageMasterId = packageData.PackageMasterId,
                        PackageName     = packageData.PackageName,
                        CreatedDate     = aDate,
                        IsActive        = true,
                        IsDeleted       = false,
                    };
                    _db.InvPackageMasters.Add(aPackageMaster);
                    _db.SaveChanges();

                    foreach (var aData in productList)
                    {
                        InvPackageDetail aPackageDetails = new InvPackageDetail()
                        {
                            PackageMasterId = aPackageMaster.PackageMasterId,
                            ProductId       = aData.ProductId,
                            ProductQuantity = aData.ProductQuantity,
                            IsActive        = true,
                            IsDeleted       = false,
                            CreatedDate     = aDate,
                        };
                        _db.InvPackageDetails.Add(aPackageDetails);
                    }
                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "New Package Successfully Saved"));
                }
                catch (Exception)
                {
                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Failed to  Save New Package"));
                }
            }
        }
Пример #2
0
 public void Save()
 {
     try
     {
         _db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #3
0
        public ResponseModel UpdateASoldProducData(InvOutletInvoiceDetail aObj)
        {
            try
            {
                DateTime aDate = DateTime.Now;

                InvOutletInvoiceDetail invOutletInvoiceDetail = _db.InvOutletInvoiceDetails.Find(aObj.OutletInvoiceDetailsId);
                invOutletInvoiceDetail.IsActive        = false;
                invOutletInvoiceDetail.ModifiedDate    = aDate;
                invOutletInvoiceDetail.ProductQuantity = aObj.ProductQuantity;
                invOutletInvoiceDetail.UnitPrice       = aObj.UnitPrice;
                invOutletInvoiceDetail.TotalPrice      = aObj.TotalPrice;
                invOutletInvoiceDetail.IsEdited        = true;
                _db.InvOutletInvoiceDetails.Attach(invOutletInvoiceDetail);
                _db.Entry(invOutletInvoiceDetail).State = EntityState.Modified;
                _db.SaveChanges();
                return(_aModel.Respons(true, "A Product Data Successfully Updated"));
            }
            catch (Exception e)
            {
                return(_aModel.Respons(false, "Sorry! Some  Error Happned"));
            }
        }
Пример #4
0
        public ResponseModel SaveOutletWarrentyDataFromWarehouse(InvOutletWarrentyRepair aObj)
        {
            try
            {
                var invOultletWarrentyRepair = _db.InvOutletWarrentyRepairs.Find(aObj.OutletWarrentyRepairId);

                invOultletWarrentyRepair.ModifiedDate = DateTime.Now;

                if (aObj.OutletWarrentyRepairId > 0)
                {
                    //aObj.ModifiedDate = DateTime.Now;

                    invOultletWarrentyRepair.Problem      = aObj.Problem;
                    invOultletWarrentyRepair.ReturnDate   = aObj.ReturnDate;
                    invOultletWarrentyRepair.RepairCost   = aObj.RepairCost;
                    invOultletWarrentyRepair.Note         = aObj.Note;
                    invOultletWarrentyRepair.RepairStatus = aObj.RepairStatus;

                    _db.InvOutletWarrentyRepairs.Attach(invOultletWarrentyRepair);
                    _db.Entry(invOultletWarrentyRepair).State = EntityState.Modified;
                    _db.SaveChanges();

                    return(_aModel.Respons(true, "Outlet warrenty data  successfully added"));
                }
                else
                {
                    _aRepository.Update(aObj);
                    _aRepository.Save();
                    return(_aModel.Respons(true, "Outlet warrenty data  successfully added."));
                }
            }
            catch (Exception)
            {
                return(_aModel.Respons(false, "Sorry! Some Error Happned."));
            }
        }
        //public ResponseModel CreateProductDetails(ProductDetailsViewModel aObj)
        //{
        //    using (var transaction = _db.Database.BeginTransaction())
        //    {
        //        try
        //        {
        //            DateTime aDate = DateTime.Now;
        //            InvProduct aProduct = new InvProduct()
        //            {
        //                ProductId = aObj.ProductId,
        //                ProductCode = aObj.ProductCode,
        //                ProductName = aObj.ProductName,
        //                ProductMainBarCode = aObj.ProductMainBarCode,
        //                ProductFactoryBarCode = aObj.ProductFactoryBarCode,
        //                ColorId = aObj.ColorId,
        //                ItemId = aObj.ItemId,
        //                SizeId = aObj.SizeId,
        //                UoMId = aObj.UoMId,
        //                MinimumStock = aObj.MinimumStock,
        //                ProductFrontImage = aObj.ProductFrontImage,
        //                ProductBackImage = aObj.ProductBackImage,
        //                CreatedDate = aObj.CreatedDate,
        //                IsActive = aObj.IsActive,

        //            };


        //            _db.InvProducts.Add(aProduct);
        //            _db.SaveChanges();

        //            if (aObj.ProductId == 0)
        //            {
        //                InvProductPrice aProductPrice = new InvProductPrice()
        //                {
        //                    ProductId = aObj.ProductId,
        //                    ProductPriceId = aObj.ProductPriceId,
        //                    CostPrice = aObj.CostPrice,
        //                    WholeSalePrice = aObj.WholeSalePrice,
        //                    RetailPrice = aObj.RetailPrice,
        //                    CreatedDate = aObj.CreatedDate,
        //                    IsActive = true

        //                };
        //                _db.InvProductPrices.Add(aProductPrice);
        //                _db.SaveChanges();
        //                transaction.Commit();
        //                return _aModel.Respons(true, "New Produc Successfully Saevd");
        //            }



        //            else
        //            {

        //                _db.InvProducts.Attach(aProduct);
        //                _db.Entry(aProduct).State=EntityState.Modified;
        //                _db.SaveChanges();


        //                var invProductPrice = _db.InvProductPrices.Find(aObj.ProductPriceId);
        //                if ((invProductPrice.CostPrice != aObj.CostPrice) ||
        //                    (invProductPrice.WholeSalePrice != aObj.WholeSalePrice) ||
        //                    (invProductPrice.RetailPrice != aObj.RetailPrice))
        //                {
        //                    invProductPrice.IsActive = false;
        //                    invProductPrice.ModifiedDate = aDate;
        //                    _db.InvProductPrices.Attach(invProductPrice);
        //                    _db.
        //                    _db.SaveChanges();
        //                }
        //            }



        //            return null;
        //        }
        //        catch (Exception)
        //        {
        //            transaction.Rollback();
        //            return _aModel.Respons(false, "Sorry! Some Error Error Happned");
        //        }
        //    }


        //}



        public ResponseModel CreateProductDetails(ProductDetailsViewModel aObj)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime   aDate    = DateTime.Now;
                    InvProduct aProduct = new InvProduct()
                    {
                        ProductId             = aObj.ProductId,
                        ProductCode           = aObj.ProductCode,
                        ProductName           = aObj.ProductName,
                        ProductMainBarCode    = aObj.ProductMainBarCode,
                        ProductFactoryBarCode = aObj.ProductFactoryBarCode,
                        ItemId            = aObj.ItemId,
                        SizeId            = aObj.SizeId,
                        ColorId           = aObj.ColorId,
                        UoMId             = aObj.UoMId,
                        MinimumStock      = aObj.MinimumStock,
                        ProductFrontImage = aObj.ProductFrontImage,
                        ProductBackImage  = aObj.ProductBackImage,

                        CreatedDate = aDate,
                        IsActive    = aObj.ProductIsActive,
                    };

                    if ((aObj.ProductId == 0)) //this is new
                    {
                        var statusProductCode =
                            _aRepository.SelectAll().Where((pc => pc.ProductCode == aObj.ProductCode));
                        var statusProductMainBarCode =
                            _aRepository.SelectAll().Where((pc => pc.ProductMainBarCode == aObj.ProductMainBarCode));
                        var statusProductFactoryBarCode =
                            _aRepository.SelectAll()
                            .Where((pc => pc.ProductFactoryBarCode == aObj.ProductFactoryBarCode));


                        if ((aObj.ProductCode == null) || (aObj.ProductMainBarCode == null) || (aObj.ProductFactoryBarCode == null) || (aObj.RetailPrice == null) || (aObj.CostPrice == null) || (aObj.WholeSalePrice == null) || (aObj.ProductCode == null))
                        {
                            return(_aModel.Respons(true, "Plese Fill All the Required Field(s)"));
                        }


                        else if (statusProductCode.Any())
                        {
                            return(_aModel.Respons(true, "Product Code Already Exist."));
                        }

                        else if (statusProductMainBarCode.Any())
                        {
                            return(_aModel.Respons(true, "Product Main Bar Code Already Exist."));
                        }

                        else if (statusProductFactoryBarCode.Any())
                        {
                            return(_aModel.Respons(true, "Product Factory Bar Code Already Exist."));
                        }



                        else if ((aObj.ProductCode != null) && (aObj.ProductMainBarCode != null) && (aObj.ProductFactoryBarCode != null) && (aObj.CostPrice != null) && (aObj.WholeSalePrice != null) &&
                                 (aObj.RetailPrice != null))

                        {
                            _db.InvProducts.Add(aProduct);
                            _db.SaveChanges();

                            InvProductPrice aProductPrice = new InvProductPrice()
                            {
                                ProductPriceId = aObj.ProductPriceId,
                                ProductId      = aProduct.ProductId,
                                CostPrice      = aObj.CostPrice,
                                WholeSalePrice = aObj.WholeSalePrice,
                                RetailPrice    = aObj.RetailPrice,
                                CreatedDate    = aDate,
                                IsActive       = true
                            };



                            _db.InvProductPrices.Add(aProductPrice);
                            _db.SaveChanges();

                            transaction.Commit();
                            return(_aModel.Respons(true, "New Product Successfully Saved"));
                        }

                        else
                        {
                            _db.SaveChanges();
                            transaction.Commit();
                            return(_aModel.Respons(true, "Failed to  Save New Product"));
                        }
                    }

                    else if ((aObj.ProductId > 0))
                    {
                        _db.InvProducts.Attach(aProduct);
                        _db.Entry(aProduct).State = EntityState.Modified;
                        _db.SaveChanges();

                        var invProduct      = _db.InvProducts.Find(aObj.ProductId);
                        var invProductPrice = _db.InvProductPrices.Find(aObj.ProductPriceId);

                        if ((aObj.ProductCode == null) || (aObj.ProductMainBarCode == null) || (aObj.ProductFactoryBarCode == null) || (aObj.RetailPrice == null) || (aObj.CostPrice == null) || (aObj.WholeSalePrice == null) || (aObj.ProductCode == null))
                        {
                            return(_aModel.Respons(true, "Plese Fill All the Required Field(s)"));
                        }


                        else if (((aObj.ProductCode == invProduct.ProductCode) && (aObj.ProductCode != null)) && (aObj.ProductMainBarCode != null) && (aObj.ProductFactoryBarCode != null) && (aObj.ProductCode != null) && (aObj.CostPrice != null) &&
                                 (aObj.WholeSalePrice != null) && (aObj.RetailPrice != null)) // During edit previous saved Product code must be same(not changed).And required fields musnt not null.
                        {
                            //start price checking logic



                            if ((invProductPrice.CostPrice != aObj.CostPrice) || (invProductPrice.WholeSalePrice != aObj.WholeSalePrice) || (invProductPrice.RetailPrice != aObj.RetailPrice))
                            {
                                //inactive previous price
                                invProductPrice.IsActive     = false;
                                invProductPrice.ModifiedDate = aDate;

                                _db.InvProductPrices.Attach(invProductPrice);
                                _db.Entry(invProductPrice).State = EntityState.Modified;
                                _db.SaveChanges();

                                //creaete new price
                                InvProductPrice aProductPrice = new InvProductPrice()
                                {
                                    ProductPriceId = aObj.ProductPriceId,
                                    ProductId      = aObj.ProductId,
                                    CostPrice      = aObj.CostPrice,
                                    WholeSalePrice = aObj.WholeSalePrice,
                                    RetailPrice    = aObj.RetailPrice,
                                    CreatedDate    = aDate,
                                    IsActive       = true
                                };

                                _db.InvProductPrices.Add(aProductPrice);
                                _db.SaveChanges();
                            }

                            transaction.Commit();
                            return(_aModel.Respons(true, "New Product Successfully Updated"));
                        }
                    }



                    else
                    {
                        transaction.Commit();
                        return(_aModel.Respons(true, "Failed to Updated a Product"));
                    }
                } // end of Try section



                catch (Exception e)
                {
                    transaction.Rollback();
                    return(_aModel.Respons(false, "Sorry! Some Error Error Happned"));
                }
            }
        }
Пример #6
0
        public ResponseModel UpdateASingleProducDataOfWarehousePO(InvWarehousePODetail aObj)
        {
            try
            {
                DateTime aDate = DateTime.Now;

                InvWarehousePODetail aInvWarehousePODetail = _db.InvWarehousePODetails.Find(aObj.WarehousePODetailsId);
                aInvWarehousePODetail.IsActive        = false;
                aInvWarehousePODetail.ModifiedDate    = aDate;
                aInvWarehousePODetail.ProductQuantity = aObj.ProductQuantity;
                // aInvWarehousePODetail.IsEdited = true;
                _db.InvWarehousePODetails.Attach(aInvWarehousePODetail);
                _db.Entry(aInvWarehousePODetail).State = EntityState.Modified;
                _db.SaveChanges();
                return(_aModel.Respons(true, "New Product Quantity Successfully Updated"));
            }
            catch (Exception e)
            {
                return(_aModel.Respons(false, "Sorry! Some  Error Happned"));
            }
        }
Пример #7
0
        public ResponseModel CreateWarehousePODetails()
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime aDate = DateTime.Now;
                    //InvWarehousePOMaster aOutletPoMaster = new InvWarehousePOMaster()
                    //{
                    //    WarehousePOMasterId = WarehousePOData.WarehousePOMasterId,
                    //    WarehouseName = WarehousePOData.WarehouseName,
                    //    Status = false,
                    //    CreatedDate = aDate,
                    //};

                    //if (WarehousePOData.WarehousePOMasterId == 0)
                    //{
                    //    _db.InvWarehousePOMasters.Add(aOutletPoMaster);
                    //    _db.SaveChanges();

                    //    foreach (var aData in productList)
                    //    {
                    //        InvWarehousePODetail aOutletPoDetails = new InvWarehousePODetail()
                    //        {
                    //            WarehousePOMasterId = aOutletPoMaster.WarehousePOMasterId,
                    //            ProductId = aData.ProductId,
                    //            ProductQuantity = aData.ProductQuantity,
                    //            CreatedDate = aDate,

                    //        };
                    //        _db.InvWarehousePODetails.Add(aOutletPoDetails);
                    //    }
                    //    _db.SaveChanges();
                    //    transaction.Commit();
                    //    return _aModel.Respons(true, "New WarehousePO Successfully Saved");
                    //}

                    //else if (WarehousePOData.WarehousePOMasterId > 0)
                    //{
                    //    _db.InvWarehousePOMasters.Attach(aOutletPoMaster);
                    //    _db.Entry(aOutletPoMaster).State = EntityState.Modified;
                    //    _db.SaveChanges();

                    //    var invPoDetails = _db.InvWarehousePODetails.Find(WarehousePOData.WarehousePODetailsId);

                    //    invPoDetails.IsActive = false;
                    //    invPoDetails.ModifiedDate = aDate;

                    //    _db.InvWarehousePODetails.Attach(invPoDetails);
                    //    _db.Entry(invPoDetails).State = EntityState.Modified;
                    //    _db.SaveChanges();

                    //    foreach (var aData in productList)
                    //    {
                    //        InvWarehousePODetail aOutletPoDetails = new InvWarehousePODetail()
                    //        {
                    //            WarehousePOMasterId = aOutletPoMaster.WarehousePOMasterId,
                    //            ProductId = aData.ProductId,
                    //            ProductQuantity = aData.ProductQuantity,
                    //            CreatedDate = aDate,
                    //        };
                    //        _db.InvWarehousePODetails.Add(aOutletPoDetails);
                    //        _db.SaveChanges();
                    //    }
                    //    transaction.Commit();
                    //    return _aModel.Respons(true, "Sorry WarehousePO Update Failed");
                    //}

                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Sorry WarehousePO Update Failed"));
                }
                catch (Exception)
                {
                    _db.SaveChanges();
                    transaction.Rollback();
                    return(_aModel.Respons(true, "Sorry Some Error Happned"));
                }
            }
        }
        public ResponseModel OutletPoReturnDetails(OutletPOReturnDetailsViewModel OutletPOReturnData, List <ProductOutletPOReturnVM> productList)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime aDate = DateTime.Now;

                    InvOutletPOReturnMaster aOutletPOReturnMaster = new InvOutletPOReturnMaster()
                    {
                        OutletPOReturnMasterId    = OutletPOReturnData.OutletPOReturnMasterId,
                        Original_OutletPOMasterId = OutletPOReturnData.OutletPOMasterId,
                        WarehouseId = OutletPOReturnData.WarehouseId, ///////When Identity will complete then we takeidies from WarehouseId and Outletet Id w
                        OutletId    = OutletPOReturnData.OutletId,

                        //WarehouseId=1,
                        //OutletId =1,
                        Status      = 0,
                        IsActive    = true,
                        IsChanged   = false,
                        IsDeleted   = false,
                        IsEdited    = false,
                        IsReceived  = false,
                        IsReturned  = 1,
                        CreatedDate = aDate,
                    };

                    if (OutletPOReturnData.OutletPOReturnMasterId == 0)
                    {
                        _db.InvOutletPOReturnMasters.Add(aOutletPOReturnMaster);
                        _db.SaveChanges();

                        foreach (var aData in productList)
                        {
                            InvOutletPOReturnDetail aOutletPOReturnDetail = new InvOutletPOReturnDetail()
                            {
                                OutletPOReturnMasterId     = aOutletPOReturnMaster.OutletPOReturnMasterId,
                                OutletPOReturnDetailsId    = aData.OutletPOReturnDetailsId,
                                Original_OutletPODetailsId = aData.OutletPODetailsId,
                                ProductId       = aData.ProductId,
                                ProductQuantity = aData.ProductQuantity,
                                IsActive        = true,
                                IsChanged       = false,
                                IsDeleted       = false,
                                IsEdited        = false,
                                IsReceived      = false,
                                IsReturned      = 1,
                                CreatedDate     = aDate,
                            };
                            _db.InvOutletPOReturnDetails.Add(aOutletPOReturnDetail);
                            _db.SaveChanges();
                        }
                        _db.SaveChanges();
                        transaction.Commit();
                        return(_aModel.Respons(true, "Outlet PO return request Successful."));
                    }

                    else if (OutletPOReturnData.OutletPOReturnMasterId > 0)
                    {
                        _db.InvOutletPOReturnMasters.Attach(aOutletPOReturnMaster);
                        _db.Entry(aOutletPOReturnMaster).State = EntityState.Modified;
                        _db.SaveChanges();

                        var invOutletPOReturnDetails = _db.InvOutletPOReturnDetails.Find(OutletPOReturnData.OutletPOReturnDetailsId);

                        invOutletPOReturnDetails.IsActive     = false;
                        invOutletPOReturnDetails.ModifiedDate = aDate;

                        _db.InvOutletPOReturnDetails.Add(invOutletPOReturnDetails);
                        _db.Entry(invOutletPOReturnDetails).State = EntityState.Modified;
                        _db.SaveChanges();

                        foreach (var aData in productList)
                        {
                            InvOutletPOReturnDetail aOutletPOReturnDetail = new InvOutletPOReturnDetail()
                            {
                                OutletPOReturnMasterId     = aOutletPOReturnMaster.OutletPOReturnMasterId,
                                OutletPOReturnDetailsId    = aData.OutletPOReturnDetailsId,
                                Original_OutletPODetailsId = aData.OutletPODetailsId,
                                ProductId       = aData.ProductId,
                                ProductQuantity = aData.ProductQuantity,
                                IsActive        = true,
                                CreatedDate     = aDate
                            };
                            _db.InvOutletPOReturnDetails.Add(aOutletPOReturnDetail);
                            _db.Entry(aOutletPOReturnDetail).State = EntityState.Modified;
                            _db.SaveChanges();
                        }
                        transaction.Commit();
                        return(_aModel.Respons(true, "Successfully  Outlet PO returned "));
                    }
                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Sorry Outlet PO returned failed"));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(_aModel.Respons(true, "Sorry Some Error Happned"));
                }
            }
        }
        public ResponseModel CreateOutletSaleUIDetails(OutletSaleUIDetailsViewModel OutletSaleUIData, List <OutletSaleUIVM> productList)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime aDate = DateTime.Now;


                    InvOutletInvoiceMaster aOutletSaleInvoiceMaster = new InvOutletInvoiceMaster()
                    {
                        OutletInvoiceMasterId = OutletSaleUIData.OutletInvoiceMasterId,
                        OutletSaleInvoiceNo   = Convert.ToInt32(_invoiceNo.GetNewInvoiceNo()),
                        //OutletId = OutletSaleUIData.OutletId,
                        OutletId     = 1,
                        CustomerId   = 1, //// Now default value is 1 but after add Identity it will be >> CustomerId = OutletSaleUIData.CustomerId,
                        SalePersonId = 1, /////Now default value is 1 but after add Identity it will be >>SalePersonId = OutletSaleUIData.SalePersonId,


                        TotalItem       = OutletSaleUIData.TotalItem,
                        TotalGrandPrice = OutletSaleUIData.TotalGrandPrice,
                        VAT             = OutletSaleUIData.VAT,
                        PaymentMode     = OutletSaleUIData.PaymentMode,
                        Cash            = OutletSaleUIData.Cash,
                        Credit          = OutletSaleUIData.Credit,
                        Discount        = OutletSaleUIData.Discount,
                        Rounding        = OutletSaleUIData.Rounding,
                        PayableAmount   = OutletSaleUIData.PayableAmount,
                        PaidAmount      = OutletSaleUIData.PaidAmount,
                        DueOrRefund     = OutletSaleUIData.DueOrRefund,

                        //IsFullPaid = OutletSaleUIData.IsFullPaid,
                        IsActive  = true,
                        IsChanged = false,
                        IsDeleted = false,
                        IsEdited  = false,


                        IsReturned  = -1,////////
                        Status      = 2,
                        Note        = "Sold",
                        CreatedDate = DateTime.Now,
                    };
                    aOutletSaleInvoiceMaster.IsFullPaid = OutletSaleUIData.DueOrRefund <= 0;   //////////OR, if (OutletSaleUIData.DueOrRefund <= 0) { aOutletSaleInvoiceMaster.IsFullPaid = true; } else { aOutletSaleInvoiceMaster.IsFullPaid = false; }
                    //aOutletSaleInvoiceMaster.OutletSaleInvoiceNo = aDate.Year +''+ aDate.Month +''+ aDate.Day +''+ aOutletSaleInvoiceMaster.OutletId;
                    // var invoiceId = aDate.Year().toString().substr(2) + "" + (aDate.Month() + 1) + "" + (aDate.Day() + "" + 1);

                    if (OutletSaleUIData.OutletInvoiceMasterId == 0)
                    {
                        if ((OutletSaleUIData.Cash > 0) && (OutletSaleUIData.Credit <= 0) && (OutletSaleUIData.PaidAmount > 0))
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "Cash";
                        }
                        else if ((OutletSaleUIData.Credit > 0) && (OutletSaleUIData.Cash <= 0) && (OutletSaleUIData.PaidAmount > 0))
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "Credit";
                        }
                        else if ((OutletSaleUIData.Cash > 0) && (OutletSaleUIData.Credit > 0) && (OutletSaleUIData.PaidAmount > 0))
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "Cash & Credit";
                        }
                        else
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "None";
                        }
                        _db.InvOutletInvoiceMasters.Add(aOutletSaleInvoiceMaster);
                        _db.SaveChanges();


                        foreach (var aData in productList)
                        {
                            //break;
                            InvOutletInvoiceDetail aOutletSaleInvoiceDetails = new InvOutletInvoiceDetail()
                            {
                                OutletInvoiceMasterId = aOutletSaleInvoiceMaster.OutletInvoiceMasterId,
                                ProductId             = aData.ProductId,
                                ProductQuantity       = aData.ProductQuantity,
                                Discount = aData.Discount,
                                //DiscountPercent = aData.DiscountPercent,
                                UnitPrice   = aData.UnitPrice,
                                TotalPrice  = aData.TotalPrice,
                                IsActive    = true,
                                IsChanged   = false,
                                IsDeleted   = false,
                                IsEdited    = false,
                                IsReturned  = -1,
                                Note        = "Sold",
                                CreatedDate = DateTime.Now
                            };
                            _db.InvOutletInvoiceDetails.Add(aOutletSaleInvoiceDetails);
                            _db.SaveChanges();

                            InvOutletStock aStock = new InvOutletStock()
                            {
                                ProductId = aData.ProductId,
                                //OutletId = aData.OutletId,
                                OutletId            = aOutletSaleInvoiceMaster.OutletId,
                                IsActive            = true,
                                IsChanged           = false,
                                IsDeleted           = false,
                                IsEdited            = false,
                                IsReturned          = -1,
                                InOut               = 2,
                                Note                = "Sold",
                                OutletStockQuantity = aData.ProductQuantity,
                                CreatedDate         = DateTime.Now
                            };
                            _db.InvOutletStocks.Add(aStock);
                            _db.SaveChanges();
                        }
                        _db.SaveChanges();
                        transaction.Commit();
                        var invoiceData = _db.spSaleInvoice(aOutletSaleInvoiceMaster.OutletSaleInvoiceNo).ToList();
                        //return _aModel.Respons(true, "Sale Info Successfully Saved");
                        return(_aModel.Respons(invoiceData));
                    }

                    else if (OutletSaleUIData.OutletInvoiceMasterId > 0)
                    {
                        _db.InvOutletInvoiceMasters.Attach(aOutletSaleInvoiceMaster);
                        _db.Entry(aOutletSaleInvoiceMaster).State = EntityState.Modified;
                        _db.SaveChanges();

                        var invOutletInvoice = _db.InvOutletInvoiceDetails.Find(OutletSaleUIData.OutletInvoiceDetailsId);

                        invOutletInvoice.IsActive     = false;
                        invOutletInvoice.ModifiedDate = DateTime.Now;

                        _db.InvOutletInvoiceDetails.Attach(invOutletInvoice);
                        _db.Entry(invOutletInvoice).State = EntityState.Modified;
                        _db.SaveChanges();

                        foreach (var aData in productList)
                        {
                            InvOutletInvoiceDetail aOutletSaleInvoiceDetails = new InvOutletInvoiceDetail()
                            {
                                OutletInvoiceMasterId = aOutletSaleInvoiceMaster.OutletInvoiceMasterId,
                                ProductId             = aData.ProductId,
                                ProductQuantity       = aData.ProductQuantity,
                                CreatedDate           = DateTime.Now,
                            };
                            _db.InvOutletInvoiceDetails.Add(aOutletSaleInvoiceDetails);
                            _db.Entry(aOutletSaleInvoiceDetails).State = EntityState.Modified;
                            _db.SaveChanges();
                        }
                        transaction.Commit();
                        return(_aModel.Respons(true, "Successfully Updated  Sale Data"));
                    }
                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Sorry Failed to Update  Sale Data"));
                }
                catch (Exception ex)
                {
                    //_db.SaveChanges();
                    transaction.Rollback();
                    return(_aModel.Respons(true, "Sorry Some Error Happned"));
                }
            }
        }
        public ResponseModel CreateStudentDetails(StudentDetails aObj)
        {
            //_aRepository.Insert(aObj);
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (aObj.StudentId == 0)
                    {
                        //var status = _aRepository.SelectAll().Where(a => a.StudentCode == aObj.StudentCode);
                        //if (status.Any())
                        //{
                        //    return _aModel.Respons(false, "Student Code Already Exist.");
                        //}

                        DateTime aDate = DateTime.Now;

                        TestStudent aStudent = new TestStudent()
                        {
                            StudentName  = aObj.StudentName,
                            StudentPhone = aObj.StudentPhone
                        };


                        //aObj.CreatedDate = aDate;
                        _db.TestStudents.Add(aStudent);
                        _db.SaveChanges();

                        TestStudentAddress aStudentAddress = new TestStudentAddress()
                        {
                            Address   = aObj.Address,
                            Country   = aObj.Country,
                            StudentId = aStudent.StudentId
                        };
                        // List<TestStudentAddress> aStudentAddress;
                        //foreach (var testStudentAddress in aStudentAddress)
                        //{
                        //    _db.TestStudentAddresses.Add(testStudentAddress);
                        //}
                        //_db.SaveChanges();
                        _db.TestStudentAddresses.Add(aStudentAddress);
                        // throw new Exception("good");

                        TestStudentHistory aStudentHistory = new TestStudentHistory()
                        {
                            HistoryDetials = aObj.HistoryDetials,
                            HistoryTitle   = aObj.HistoryTitle,
                            StudentId      = aStudent.StudentId
                        };
                        _db.TestStudentHistories.Add(aStudentHistory);
                        _db.SaveChanges();


                        transaction.Commit();
                        return(_aModel.Respons(true, "New Student Successfully Saved"));
                    }
                    else
                    {
                        DateTime aDate = DateTime.Now;
                        //aObj.CreatedDate = aDate;
                        //_aRepository.Update(aObj);
                        //_aRepository.Save();
                        return(_aModel.Respons(true, "New Student Successfully Updated"));
                    }
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(_aModel.Respons(false, "Sorry! Some Error Error Happned"));
                }
            }
        }
Пример #11
0
        /// <summary>
        /// ///Clock frock
        /// </summary>
        /// <param name="WarehousePOData"></param>
        /// <param name="productList"></param>
        /// <returns></returns>
        public ResponseModel CreateWarehousePODetails(WarehousePODetailsViewModel WarehousePOData, List <ProductWarehousePOVM> productList)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime             aDate = DateTime.Now;
                    InvWarehousePOMaster aWarehousePoMaster = new InvWarehousePOMaster()
                    {
                        // WarehouseId = WarehousePOData.WarehouseId,
                        WarehousePOMasterId = WarehousePOData.WarehousePOMasterId,
                        WarehouseId         = 1, //////////In UI there is no Warehouse Id so initialy warehouse id =1 sending to database
                        SupplierId          = WarehousePOData.SupplierId,
                        UniqueId            = WarehousePOData.UniqueId,
                        POReference         = WarehousePOData.POReference,
                        Status      = 0,
                        IsActive    = true,
                        IsDeleted   = false,
                        IsEdited    = false,
                        IsReturned  = false,
                        CreatedDate = aDate,
                    };

                    if (WarehousePOData.WarehousePOMasterId == 0)
                    {
                        _db.InvWarehousePOMasters.Add(aWarehousePoMaster);
                        _db.SaveChanges();

                        foreach (var aData in productList)
                        {
                            InvWarehousePOInvoiceDetail aWarehousePoInvoiceDetails = new InvWarehousePOInvoiceDetail()
                            {
                                WarehousePOInvoiceDetailsId   = aData.WarehousePOInvoiceDetailsId,
                                Original_WarehousePODetailsId = aData.WarehousePODetailsId,
                                ProductId       = aData.ProductId,
                                ProductQuantity = aData.OrderedQuantity,
                                IsActive        = true,
                                IsDeleted       = false,
                                IsEdited        = false,
                                IsReturned      = false,
                                CreatedDate     = aDate,
                            };
                            _db.InvWarehousePOInvoiceDetails.Add(aWarehousePoInvoiceDetails);
                            _db.SaveChanges();
                        }
                        _db.SaveChanges();
                        transaction.Commit();
                        return(_aModel.Respons(true, "Warehouse PO successfully returned"));
                    }
                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Sorry Warehouse PO returned Failed"));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(_aModel.Respons(true, "Sorry Some Error Happned"));
                }
            }
        }