Ejemplo n.º 1
0
        public HttpResponseMessage ConfirmOrder([FromBody] ConfirmOrderDto codto)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Hatali model!"));
            }
            string cookie = codto.Cookie;
            User   user   = _userDal.GetUserByCookie(cookie);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User Bulunamadı!"));
            }

            List <List <int> > sepetArray = JsonConvert.DeserializeObject <List <List <int> > >(codto.OrderArray);
            int     addressID             = codto.AddressID;
            int     regionID    = _addressDal.Get(x => x.ID == addressID).RegionID;
            int     companyID   = sepetArray[0][2];
            int     branchID    = _branchDal.Get(x => x.CompanyID == companyID && x.RegionID == regionID).ID;
            bool    paymentType = codto.PaymentType == 0;
            decimal totalPrice  = 0;

            int orderCount = sepetArray.Count;

            for (int i = 0; i < orderCount; i++)
            {
                totalPrice += (_menuDal.GetByID(sepetArray[i][0]).Price) * sepetArray[i][1];
            }

            Order o = new Order()
            {
                BranchID    = branchID,
                AddressID   = addressID,
                IsActive    = true,
                OrderDate   = DateTime.Now,
                PaymentType = paymentType,
                TotalPrice  = totalPrice
            };

            _orderDal.Add(o);

            for (int i = 0; i < orderCount; i++)
            {
                OrderDetail od = new OrderDetail()
                {
                    IsCompleted = true,
                    MenuID      = sepetArray[i][0],
                    OrderID     = o.ID,
                    Quantity    = sepetArray[i][1],
                    TotalAmount = _menuDal.GetByID(sepetArray[i][0]).Price *sepetArray[i][1]
                };
                _orderDetailDal.Add(od);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, "Başarılı"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AcceptDetailsToWarehouse([FromBody] ConfirmOrderDto confirmOrderDto)
        {
            var order = await _context.DetailOrders
                        .Include(o => o.DetailOrderRows)
                        .FirstOrDefaultAsync(o => o.DetailOrderId == confirmOrderDto.DetailOrderId);

            if (order == null)
            {
                return(BadRequest());
            }

            var warehouseDetails = await _context.WarehouseDetails.Where(wd => wd.WarehouseId == confirmOrderDto.WarehouseId).ToListAsync();

            foreach (var row in order.DetailOrderRows)
            {
                var warehouseDetail = warehouseDetails.FirstOrDefault(wd => wd.DetailId == row.DetailId);

                if (warehouseDetail == null)
                {
                    warehouseDetail = new WarehouseDetails()
                    {
                        WarehouseId = confirmOrderDto.WarehouseId,

                        DetailId = row.DetailId.Value,

                        Count = row.Count
                    };
                }
                else
                {
                    warehouseDetail.Count += row.Count;
                }

                await _context.Comings.AddAsync(new Comings
                {
                    Date = DateTime.UtcNow,

                    DetailOrderRowId = row.DetailOrderRowId,

                    WarehouseDetail = warehouseDetail,

                    WorkerId = confirmOrderDto.WorkerId
                });
            }

            await _context.SaveChangesAsync();

            return(NoContent());
        }