public async Task <IActionResult> AddSupply([FromBody] AppSupply model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var addedSupply = await supplyRepo.AddSupplyInfo(model);

                    if (addedSupply != null)
                    {
                        return(Ok(addedSupply));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception excp)
                {
                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <AppSupply> UpdateSupply(AppSupply supply)
        {
            if (db != null)
            {
                //Delete that post
                db.AppSupply.Update(supply);

                //Commit the transaction
                await db.SaveChangesAsync();
            }

            return(supply);
        }
Exemplo n.º 3
0
        public async Task <AppSupply> AddSupplyInfo(AppSupply supply)
        {
            if (db != null)
            {
                supply.AppSupplyId = Guid.NewGuid();
                supply.CreatedDate = DateTime.Now;
                await db.AppSupply.AddAsync(supply);

                await db.SaveChangesAsync();

                return(supply);
            }

            return(supply);
        }
        public async Task <IActionResult> UpdateSupply([FromBody] AppSupply supply)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await supplyRepo.UpdateSupply(supply);

                    return(Ok());
                }
                catch (Exception excp)
                {
                    if (excp.GetType().FullName ==
                        "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }