Esempio n. 1
0
        public async Task <IActionResult> AddSeller([FromBody] AppSeller model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.AppSellerId = Guid.NewGuid();
                    var appSeller = await blueRepository.AddSeller(model);

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

            return(BadRequest());
        }
        public async Task <AppSeller> AddSeller(AppSeller seller)
        {
            if (db != null)
            {
                await db.AppSeller.AddAsync(seller);

                await db.SaveChangesAsync();

                return(seller);
            }

            return(seller);
        }
        public async Task <AppSeller> UpdateSeller(AppSeller seller)
        {
            if (db != null)
            {
                //Delete that post
                db.AppSeller.Update(seller);

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

            return(seller);
        }
        public async Task <int> DeleteSeller(AppSeller seller)
        {
            int result = 0;

            if (db != null)
            {
                //Find the post for specific post id
                var sellerDel = await db.AppSeller.FirstOrDefaultAsync(p => p.AppSellerId == seller.AppSellerId);

                if (sellerDel != null)
                {
                    //Delete that post
                    db.AppSeller.Remove(sellerDel);

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

            return(result);
        }
Esempio n. 5
0
        public async Task <IActionResult> UpdateSeller([FromBody] AppSeller model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await blueRepository.UpdateSeller(model);

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

                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }
Esempio n. 6
0
        public async Task <IActionResult> DeleteSeller([FromBody] AppSeller seller)
        {
            int result = 0;

            if (seller == null)
            {
                return(BadRequest());
            }

            try
            {
                result = await blueRepository.DeleteSeller(seller);

                if (result == 0)
                {
                    return(NotFound());
                }
                return(Ok());
            }
            catch (Exception excp)
            {
                return(BadRequest(excp));
            }
        }