Esempio n. 1
0
        public ServiceResult <StoreInvoicing> UpdatestoreInvoicing(StoreInvoicing storeInvoicing)
        {
            var errors = new List <string>();

            if (_context.StoreInvoicings.Any(x => x.Id == storeInvoicing.Id))
            {
                storeInvoicing.IsDelete = true;
                storeInvoicing.StoreInvoicingUpdateDate = DateTime.Now;
                // errors.Add("Mobile is duplicate");
            }

            if (errors.Any())
            {
                return(ServiceResult <StoreInvoicing> .Failed(errors));
            }
            _context.Add(storeInvoicing);
            // _context.Entry(storeInvoicing).State = EntityState.Modified;
            var result = _context.SaveChanges();

            if (result > 0)
            {
                return(ServiceResult <StoreInvoicing> .Succeed(storeInvoicing));
            }
            return(ServiceResult <StoreInvoicing> .Failed(new List <string> {
                "Data not inserted"
            }));
        }
        public ServiceResult <Products> AddSubmitOrder(Products product, int customerId)
        {
            StoreInvoicingDetails storeInvoicingDetails = new StoreInvoicingDetails();
            StoreInvoicing        storeInvoicing        = new StoreInvoicing();

            storeInvoicingDetails.ProductId    = product.Id;
            storeInvoicingDetails.CurrentPrice = product.UnitPrice;
            storeInvoicingDetails.Qty          = product.NumberOfOrders;
            storeInvoicingDetails.InvoicingDetailCreateDate = DateTime.Now;
            storeInvoicingDetails.InvoicingDetailStatus     = 1;//sabte sefaresh

            storeInvoicing.CustomerId = customerId;
            storeInvoicing.StoreInvoicingCreateDate = DateTime.Now;
            storeInvoicing.InvoicingDetailId        = storeInvoicingDetails.Id;
            _context.StoreInvoicingDetails.Add(storeInvoicingDetails);
            _context.StoreInvoicings.Add(storeInvoicing);


            var result = _context.SaveChanges();

            if (result > 0)
            {
                return(ServiceResult <Products> .Succeed(product));
            }
            return(ServiceResult <Products> .Failed(new List <string> {
                "Data not inserted!!!"
            }));
        }
Esempio n. 3
0
        public IActionResult DeleteStoreInvoicing(int id, StoreInvoicing storeInvoicings)
        {
            var result = _storeInvoicing.DeletestoreInvoicing(id);

            if (result.IsSucceed)
            {
                if (result.Data != null)
                {
                    return(Ok(result.Data));
                }
                return(NotFound());
            }
            return(BadRequest(string.Join(",", result.Errors)));
        }
Esempio n. 4
0
        public IActionResult UpdateStoreInvoicing(int id, StoreInvoicing storeInvoicings)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(BadRequest(string.Join(",", errors)));
            }
            var result = _storeInvoicing.UpdatestoreInvoicing(storeInvoicings);

            if (result.IsSucceed)
            {
                return(Ok(result.Data));
            }
            return(BadRequest(string.Join(",", result.Errors)));
        }
Esempio n. 5
0
        public ServiceResult <StoreInvoicing> AddstoreInvoicing(string productId, int customerId)
        {
            var errors = new List <string>();

            if (errors.Any())
            {
                return(ServiceResult <StoreInvoicing> .Failed(errors));
            }
            StoreInvoicing storeInvoicing = _context.StoreInvoicings.SingleOrDefault(s => s.CustomerId == 1 && s.StoreInvoicingStatus != 1);

            if (storeInvoicing == null)
            {
                storeInvoicing = new StoreInvoicing
                {
                    CustomerId = 1,//customerId,
                    //StoreInvoicingCreateDate = DateTime.Now,
                    StoreInvoicingStatus = 0,
                    IsDelete             = false
                };
                _context.StoreInvoicings.Add(storeInvoicing);
                _context.StoreInvoicingDetails.Add(new StoreInvoicingDetails()
                {
                    InvoicingId               = storeInvoicing.InvoicingDetailId,
                    ProductId                 = 1,//productId,
                    CurrentPrice              = _context.Products.Find(productId).UnitPrice,
                    Qty                       = _context.Products.Find(productId).NumberOfOrders,
                    TotalAmount               = 0,
                    LaborCustomerItem         = 5000,
                    InvoicingDetailCreateDate = DateTime.Now,
                    InvoicingDetailStatus     = 1,
                    IsDelete                  = false
                });
                var result = _context.SaveChanges();

                if (result > 0)
                {
                    return(ServiceResult <StoreInvoicing> .Succeed(storeInvoicing));
                }
            }
            else
            {
                var details = _context.StoreInvoicingDetails.SingleOrDefault(s =>
                                                                             s.InvoicingId == storeInvoicing.InvoicingDetailId &&
                                                                             s.ProductId == 1 /*productId*/);
                if (details == null)
                {
                    _context.StoreInvoicingDetails.Add(new StoreInvoicingDetails()
                    {
                        InvoicingId               = storeInvoicing.InvoicingDetailId,
                        ProductId                 = 1,//productId,
                        CurrentPrice              = _context.Products.Find(productId).UnitPrice,
                        Qty                       = _context.Products.Find(productId).NumberOfOrders,
                        TotalAmount               = 0,
                        LaborCustomerItem         = 5000,
                        InvoicingDetailCreateDate = DateTime.Now,
                        InvoicingDetailStatus     = 1,
                        IsDelete                  = false
                    });
                }
                else
                {
                    details.Qty += 1;
                    _context.Update(details);
                }

                var result = _context.SaveChanges();
                UpdateTotalAmount(storeInvoicing.InvoicingDetailId);
                if (result > 0)
                {
                    return(ServiceResult <StoreInvoicing> .Succeed(storeInvoicing));
                }
            }


            return(ServiceResult <StoreInvoicing> .Failed(new List <string> {
                "Data not inserted!!!"
            }));
        }