예제 #1
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.ProductID)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutLineInfo(int id, LineInfo lineInfo)
        {
            if (id != lineInfo.LineInfoID)
            {
                return(BadRequest());
            }

            _context.Entry(lineInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LineInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> DiscardRemainOrder(PlanInfo plan)
        {
            try
            {
                var Plan         = _context.Plans.Single(x => x.PlanInfoID == plan.PlanInfoID);
                var RemainOrders = _context.Entry(Plan).Collection(b => b.Orders).Query().Where(o => o.IsConfirmed == false);
                await RemainOrders.ForEachAsync(o =>
                {
                    o.IsConfirmed           = true;
                    _context.Entry(o).State = EntityState.Modified;
                });

                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (DbUpdateConcurrencyException)
            {
            }
            return(NoContent());
        }
예제 #4
0
        public async Task <ActionResult <PlanInfo> > CreatePlan(PlanInfo planInfo)
        {
            var CreatedPlans = await _context.Plans.Where(x => x.LineInfoID == planInfo.LineInfoID && x.IsComplete == false).ToListAsync();

            foreach (PlanInfo Plan in CreatedPlans)
            {
                if (Plan.ProductID == planInfo.ProductID)
                {
                    return(BadRequest("Plan already created"));
                }
                else
                {
                    Plan.FinishedTime          = DateTime.Now;
                    Plan.IsComplete            = true;
                    _context.Entry(Plan).State = EntityState.Modified;
                }
            }
            _context.Plans.Add(planInfo);
            await _context.SaveChangesAsync();

            return(Ok("Plan created successfully"));
        }