public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Value,CategoryId")] InsuredItem insuredItem)
        {
            if (id != insuredItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid && insuredItem.Value >= 0)  // if form is valid and the value is greater than zero
            {
                try
                {
                    _context.Update(insuredItem);      // update context
                    await _context.SaveChangesAsync(); //commit changes to db.
                }
                catch (DbUpdateConcurrencyException)   // handle db exception
                {
                    if (!InsuredItemExists(insuredItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            SetViewBag();
            return(View(insuredItem));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Value,CategoryId")] InsuredItem insuredItem)
        {
            if (id != insuredItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(insuredItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InsuredItemExists(insuredItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            SetViewBag();
            return(View(insuredItem));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Value,CategoryId")] InsuredItem insuredItem)
        {
            if (ModelState.IsValid || insuredItem.Value >= 0)  // reject if user puts in zero or negative value
            {
                _context.Add(insuredItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            SetViewBag();
            return(View(insuredItem));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Value,CategoryId")] InsuredItem insuredItem)
        {
            // if valid form
            if (ModelState.IsValid && insuredItem.Value >= 0) // reject if user puts in zero or negative value
            {
                _context.Add(insuredItem);                    //adds to the context
                await _context.SaveChangesAsync();            // commit changes to db.

                return(RedirectToAction(nameof(Index)));      // return listing
            }
            SetViewBag();
            return(RedirectToAction(nameof(Index)));
        }
Example #5
0
        public async Task <Client> Create(string clientId, string name)
        {
            var item = new InsuredItem()
            {
                Name      = name,
                IsInsured = false
            };

            var client = await _clientsRepo.Get(clientId);

            if (client.Items == null)
            {
                client.Items = new List <InsuredItem>();
            }

            client.Items.Add(item);

            await _clientsRepo.Update(clientId, client);

            return(client);
        }
Example #6
0
 public static bool UpdateInsuredItemById(InsuredItem item)
 {
     return(DbContext.UpdateInsuredItemById(item));
 }
Example #7
0
 public static bool AddItemToExistingQuote(InsuredItem item)
 {
     return(DbContext.AddItemToExistingQuote(item));
 }
        public HttpResponseMessage UpdateInsuredItemById(InsuredItem item)
        {
            var result = QsDataRepository.UpdateInsuredItemById(item);

            return(Request.CreateResponse(result ? HttpStatusCode.OK : HttpStatusCode.NotFound, result));
        }
        public HttpResponseMessage AddItemToExistingQuote(InsuredItem item)
        {
            var result = QsDataRepository.AddItemToExistingQuote(item);

            return(Request.CreateResponse(result ? HttpStatusCode.OK : HttpStatusCode.NotFound, result));
        }