Exemple #1
0
        public async Task <IActionResult> PutRequestline(int id, Requestline requestline)
        {
            if (id != requestline.Id)
            {
                return(BadRequest());
            }

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

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

            await refreshrequestline(requestline);
            await recalculatetotal(requestline.RequestId);

            return(NoContent());
        }
        public async Task <ActionResult <Requestline> > PostRequestline(Requestline requestline)
        {
            _context.Requestlines.Add(requestline);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRequestline", new { id = requestline.Id }, requestline));
        }
Exemple #3
0
        public bool Update(int id, Requestline requestLine)   // passing in both the requestline and the id so that you can verify you are updateing the correct record
        {
            if (requestLine == null)
            {
                throw new Exception("RequestLine cannot be null");
            }
            if (id != requestLine.Id)
            {
                throw new Exception("Id and Requestline.IC must match");                      // can also check id >0 and all the instance data validity like name done under insert
            }
            // update datetime? variable Updated
            context.Entry(requestLine).State = EntityState.Modified; // state tells the status of the data in the context[same as if you had read it from database and updated
                                                                     //          context.requestline.Update(requestline);
            try {
                context.SaveChanges();                               // hover over save changes will see exceptions that can occur
                RecalcRequestTotal(requestLine.RequestId);
            } catch (DbUpdateException ex) {
                throw new Exception("RequestLinename must be unique", ex);
            } catch (Exception ex) {
                throw ex;
            }
            context.SaveChanges();
            RecalcRequestTotal(requestLine.RequestId);

            return(true);
        }
Exemple #4
0
        // the two deletes are overloading the delete methods by allowing them to pass either the id or the entire requestline in


        public bool Delete(Requestline requestLine)
        {
            context.RequestLines.Remove(requestLine);
            context.SaveChanges();
            RecalcRequestTotal(requestLine.RequestId);
            return(true);
        }
        public async Task <ActionResult <Requestline> > PostRequestline(Requestline requestline)
        {
            var request = await _context.Request.FindAsync(requestline.RequestId);

            _context.Requestline.Add(requestline);
            await RecalculateTotal(request.Id);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRequestline", new { id = requestline.Id }, requestline));
        }
 public async Task <IActionResult> PositiveQuantity(int id, Requestline requestline)
 {
     if (requestline.Quantity < 0)
     {
         requestline.Quantity = 0;
     }
     else
     {
         return(NoContent());
     }
     return(await PutRequestline(id, requestline));
 }
        public async Task <ActionResult <Requestline> > PostRequestline(Requestline requestline)
        {
            if (requestline.Quantity < 0)
            {
                requestline.Quantity = 0;
            }
            _context.Requestline.Add(requestline);
            await _context.SaveChangesAsync();

            await RecalculateTotal(requestline.RequestId, _context.Request.Find(requestline.RequestId));

            return(CreatedAtAction("GetRequestline", new { id = requestline.Id }, requestline));
        }
Exemple #8
0
 public Requestline Insert(Requestline requestLine)  //need to pass entire instance of the requestline}
 {
     if (requestLine == null)
     {
         throw new Exception("RequestLine cannot be null");
     }
     // should check requestline name is not null and maxlength of requestline namer not exceeded
     // should also check that id is not anything other than 0 because database is providing key
     //edit checking here
     context.RequestLines.Add(requestLine);
     try {
         context.SaveChanges();
         RecalcRequestTotal(requestLine.RequestId);
         // hover over save changes will see exceptions that can occur
     } catch (DbUpdateException ex) {
         throw new Exception("Username must be unique", ex);
     } catch (Exception) {
         throw;
     }
     return(requestLine);// the add will generate the id into the passed in requestline and return back here
 }
Exemple #9
0
 private async Task refreshrequestline(Requestline requestline)
 {
     _context.Entry(requestline).State = EntityState.Detached;
     await _context.Requestline.FindAsync(requestline.Id);
 }
 public async Task <IActionResult> UpdateRequestline(int id, Requestline requestline)
 {
     return(await PutRequestline(id, requestline));
 }