public async Task <IActionResult> AddDemand([FromBody] AppDemand model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    logger.LogInformation("Adding Demand in the Repository");
                    var addedDemand = await demandRepo.AddProductDemand(model);

                    if (addedDemand != null)
                    {
                        return(Ok(addedDemand));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception excp)
                {
                    logger.LogError("Error in adding Demand in the Repository " + excp.Message);

                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }
Esempio n. 2
0
        public async Task <AppDemand> UpdateDemand(AppDemand demand)
        {
            if (db != null)
            {
                //Delete that post
                db.AppDemand.Update(demand);

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

            return(demand);
        }
Esempio n. 3
0
        public async Task <AppDemand> AddProductDemand(AppDemand demand)
        {
            if (db != null)
            {
                demand.AppDemandId = Guid.NewGuid();
                demand.CreatedDate = DateTime.Now;
                await db.AppDemand.AddAsync(demand);

                await db.SaveChangesAsync();

                return(demand);
            }

            return(demand);
        }
        public async Task <IActionResult> UpdateDemand([FromBody] AppDemand demand)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await demandRepo.UpdateDemand(demand);

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

                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }