Esempio n. 1
0
 public void Remove(Gift item)
 {
     try
     {
         _dbSet.Remove(item);
         _dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
        public bool Update(Gift item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("entityToUpdate");
            }

            _dbContext.Gifts.Attach(item);
            _dbContext.Entry(item).State = EntityState.Modified;
            _dbContext.SaveChanges();

            return true;
        }
Esempio n. 3
0
        public Gift Add(Gift item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            item.Id = Tools.GetRandomKey();

            _dbSet.Add(item);
            _dbContext.SaveChanges();

            return item;
        }
Esempio n. 4
0
        public async Task<IHttpActionResult> Post(Gift gift)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception));
                return BadRequest(ModelState);
            }

            try
            {
                //Récupération de l'id de l'utilisateur en cours
                ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
                gift.OwnerUserId = user.Id;

                Gift createdGift = repository.Add(gift);
                return Ok(createdGift);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //return CreatedAtRoute("DefaultApi", new { id = product.ProductId }, product);
        }
Esempio n. 5
0
        public IHttpActionResult PutGift(string id, Gift gift)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != gift.Id)
            {
                return BadRequest();
            }
                       
            try
            {
                if (!repository.Update(gift))
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }                
            }
            catch (Exception ex) 
            {
                return NotFound();                
            }

            return StatusCode(HttpStatusCode.OK);
            
        }