コード例 #1
0
        public async Task <IActionResult> PutRequestLines(int id, RequestLines requestLines)
        {
            if (id != requestLines.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <RequestLines> > PostRequestLines(RequestLines requestLines)
        {
            _context.RequestLines.Add(requestLines);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRequestLines", new { id = requestLines.Id }, requestLines));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,RequestId,ProductId,Quantity")] RequestLines requestLines)
        {
            if (id != requestLines.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(requestLines);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RequestLinesExists(requestLines.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", requestLines.ProductId);
            ViewData["RequestId"] = new SelectList(_context.Requests, "Id", "DeliveryMode", requestLines.RequestId);
            return(View(requestLines));
        }
コード例 #4
0
        public async Task <IActionResult> PutRequestLines(int id, RequestLines requestLines)
        {
            if (id != requestLines.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                var success = RecalcuateRequestTotal(requestLines.RequestId);
                await _context.SaveChangesAsync();

                if (!success)
                {
                    return(this.StatusCode(500));
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RequestLinesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #5
0
 public static bool Insert(RequestLines requestline)
 {
     if (requestline == null)
     {
         throw new Exception("Request line cannot be null!");
     }
     context.RequestLines.Add(requestline);
     RecalcReqTotal(requestline.Id);
     return(context.SaveChanges() == 1);
 }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,RequestId,ProductId,Quantity")] RequestLines requestLines)
        {
            if (ModelState.IsValid)
            {
                _context.Add(requestLines);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", requestLines.ProductId);
            ViewData["RequestId"] = new SelectList(_context.Requests, "Id", "DeliveryMode", requestLines.RequestId);
            return(View(requestLines));
        }
コード例 #7
0
        public async Task <ActionResult <RequestLines> > PostRequestLines(RequestLines requestLines)
        {
            _context.RequestLines.Add(requestLines);
            await _context.SaveChangesAsync();

            /* CALL RECALC */
            var success = RecalculateRequestTotal(requestLines.RequestId);

            if (!success)
            {
                return(this.StatusCode(500));
            }
            return(CreatedAtAction("GetRequestLines", new { id = requestLines.Id }, requestLines));
        }
コード例 #8
0
        public static bool Delete(RequestLines requestline)
        {
            if (requestline == null)
            {
                throw new Exception("RequestLine not found");
            }
            var dbrequestline = context.RequestLines.Find(requestline.Id);

            if (dbrequestline == null)
            {
                throw new Exception("RequestLine not found");
            }
            context.RequestLines.Remove(dbrequestline);
            RecalcReqTotal(requestline.Id);
            return(context.SaveChanges() == 1);
        }
コード例 #9
0
        public static bool Update(RequestLines requestline)
        {
            if (requestline == null)
            {
                throw new Exception("RequestLine not found");
            }
            var dbrequestline = context.RequestLines.Find(requestline.Id);

            if (dbrequestline == null)
            {
                throw new Exception("RequestLine not found");
            }
            dbrequestline.Id        = requestline.Id;
            dbrequestline.RequestId = requestline.RequestId;
            dbrequestline.ProductId = requestline.ProductId;
            dbrequestline.Quantity  = requestline.Quantity;
            RecalcReqTotal(requestline.Id);
            return(context.SaveChanges() == 1);
        }