Beispiel #1
0
        public async Task <IActionResult> AddFreight([FromBody] AppFreight model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var addedFreight = await freightRepo.AddFreight(model);

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

            return(BadRequest());
        }
Beispiel #2
0
        public async Task <AppFreight> UpdateFreight(AppFreight freight)
        {
            if (db != null)
            {
                //Delete that post
                db.AppFreight.Update(freight);

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

            return(freight);
        }
Beispiel #3
0
        public async Task <AppFreight> AddFreight(AppFreight freight)
        {
            if (db != null)
            {
                freight.AppFreightId = Guid.NewGuid();
                freight.CreatedDate  = DateTime.Now;
                await db.AppFreight.AddAsync(freight);

                await db.SaveChangesAsync();

                return(freight);
            }

            return(freight);
        }
Beispiel #4
0
        public async Task <IActionResult> UpdateFreight([FromBody] AppFreight freight)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await freightRepo.UpdateFreight(freight);

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

                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }