public IActionResult Post([FromRoute] int id, [FromBody] BuyerProduct buyerProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            OrderProduct orderProduct = new OrderProduct()
            {
                OrderId = id, ProductId = buyerProduct.ProductId
            };

            _context.OrderProduct.Add(orderProduct);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (OrderExists(id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
Beispiel #2
0
        public List <BuyerProductModel> DeleteBuyerProduct(long Id, long buyerID)
        {
            List <BuyerProductModel> lstbulkproducts = new List <BuyerProductModel>();

            using (ShopDevEntities db = new ShopDevEntities())
            {
                try
                {
                    BuyerProduct product = GetProduct(db, Id);

                    db.BuyerProducts.Remove(product);
                    db.SaveChanges();
                    var lstproducts = db.BuyerProducts.Where(m => m.BuyerID == buyerID).ToList();
                    foreach (var cusprod in lstproducts)
                    {
                        BuyerProductModel objcsproducts = new BuyerProductModel();
                        cusprod.CopyProperties(objcsproducts);
                        lstbulkproducts.Add(objcsproducts);
                    }
                }
                catch (Exception)
                {
                }
                return(lstbulkproducts);
            }
        }
Beispiel #3
0
        public List <BuyerProductModel> AddBuyerProduct(BuyerProductModel productModel)
        {
            List <BuyerProductModel> lstcsproducts = new List <BuyerProductModel>();

            using (ShopDevEntities db = new ShopDevEntities())
            {
                try
                {
                    productModel.BuyerID = productModel.BuyerID == null ? 0 : productModel.BuyerID;
                    BuyerProduct buyerproduct = null;
                    int?         oldUnits     = 0;
                    if (productModel.BuyerProductlD > 0)
                    {
                        buyerproduct = db.BuyerProducts.Where(m => m.BuyerProductlD == productModel.BuyerProductlD).FirstOrDefault();
                        oldUnits     = buyerproduct.Units == null ? 0 : buyerproduct.Units;
                        var diffUnit = oldUnits - productModel.Units;
                        var product  = db.Products.Where(m => m.ProductName == productModel.ProductName).FirstOrDefault();
                        if (product != null)
                        {
                            product.Unit += diffUnit;
                        }
                    }
                    else
                    {
                        buyerproduct = new BuyerProduct();
                    }


                    productModel.CopyProperties(buyerproduct);
                    if (productModel.BuyerProductlD == 0)
                    {
                        db.BuyerProducts.Add(buyerproduct);

                        if (productModel.BuyerID > 0)
                        {
                            var oldproduct = db.Products.Where(m => m.ProductName == productModel.ProductName && m.Type == productModel.Type).FirstOrDefault();
                            if (oldproduct != null)
                            {
                                oldproduct.Unit -= productModel.Units;
                            }
                        }
                    }
                    db.SaveChanges();
                    var lstproducts = db.BuyerProducts.Where(m => m.BuyerID == productModel.BuyerID).ToList();
                    foreach (var cusprod in lstproducts)
                    {
                        BuyerProductModel objcsproduct = new BuyerProductModel();
                        cusprod.CopyProperties(objcsproduct);
                        lstcsproducts.Add(objcsproduct);
                    }
                    return(lstcsproducts);
                }
                catch (Exception)
                {
                    return(lstcsproducts);
                }
            }
        }
Beispiel #4
0
        public BuyerProduct GetProduct(ShopDevEntities db, long Id)
        {
            BuyerProduct objProduct = null;

            try
            {
                objProduct = db.BuyerProducts.Where(m => m.BuyerProductlD == Id).FirstOrDefault();
            }
            catch (Exception)
            {
            }
            return(objProduct);
        }
        public IActionResult Post([FromBody] BuyerProduct buyerProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Order order = new Order()
            {
                CustomerId = buyerProduct.BuyerId
            };

            _context.Order.Add(order);
            OrderProduct orderProduct = new OrderProduct()
            {
                OrderId = order.OrderId, ProductId = buyerProduct.ProductId
            };

            _context.OrderProduct.Add(orderProduct);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (OrderExists(order.OrderId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("GetOrder", new { id = order.OrderId }, order));
        }
Beispiel #6
0
        public IHttpActionResult test()

        {
            var prod = new ProductMaster()
            {
                GenerateDate = DateTime.Now,
                Name         = "CorporateHealth",
                State        = true,
            };
            var Buyer = new BuyerMaster()
            {
                ApiUrl          = "",
                CompanyName     = "Syne Craft",
                Email           = "*****@*****.**",
                Name            = "SyneCraft",
                State           = EntityObjects.Enaum.EntityState.active,
                CreatedDateTime = DateTime.Now,
            };
            var buyerProd = new BuyerProduct()
            {
                BuyerApiUrl     = "https://vmleads.co.uk/integrations/rest?is_test=1",
                BuyerMasterId   = 1,
                EndDate         = DateTime.Now.AddDays(25),
                IntegrationType = EntityObjects.Enaum.BuyerIntegrationType.xml,
                ProductMasterId = 3,
                Piority         = 1,
                Quata           = 100,
                StartDate       = DateTime.Now,
                State           = true,
            };
            //var buyer = new BuyerMaster()
            //{
            //    ApiUrl= "http://leadbee.leadspediatrack.com/post.do",
            //    CompanyName ="SuneCraft",
            //     CreatedDateTime = DateTime.Now,

            //};
            //_dbContext.ProductMasters.Add(prod);
            //  _dbContext.SaveChanges();
            var v         = _dbContext.ProductMasters.ToList();
            var prods     = _dbContext.BuyerMasters.ToList();
            var prodBuyer = _dbContext.BuyerProducts.ToList();

            // var v = _dbContext.CommonLeads.ToList().OrderByDescending(m=>m.Id).Where(m=>m.ProductName == "Funeral");
            // _dbContext.ProductMasters.Add(prod);
            // _dbContext.BuyerMasters.Add(Buyer);
            // _dbContext.BuyerProducts.Add(buyerProd);
            // _dbContext.SaveChanges();

            // CommonLead cmn = UtilityMethods.GetCommonLeads(1276);
            // cmn.Email = "*****@*****.**";
            // _dbContext.Entry(cmn).State = EntityState.Modified;
            // _dbContext.SaveChanges();
            // LeadTransferById(1276);

            //LifeLead life = UtilityMethods.GetProductLeadByLeadId<LifeLead>(1276, "Life");
            //life.DOB = new DateTime(1865, 2, 12);
            //_dbContext.Entry(life).State = EntityState.Modified;
            //_dbContext.SaveChanges();

            //  var vc = _dbContext.CommonLeads.Where(m => m.Id == 2321).ToList();
            //  BuyerProduct bPod = _dbContext.BuyerProducts.Where(m => m.Id == 4).FirstOrDefault();
            //  bPod.BuyerApiUrl = "http://leadbee.leadspediatrack.com/post.do";
            //   _dbContext.Entry(bPod).State = EntityState.Modified;
            //  _dbContext.SaveChanges();

            //LeadTransfer(2387);
            return(Ok(prods));
        }