예제 #1
0
        public IHttpActionResult PutKitchenType(int id, KitchenType kitchenType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != kitchenType.KitchenTypeID)
            {
                return(BadRequest());
            }

            db.Entry(kitchenType).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KitchenTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        }                                        // timpul o sa fie exprimat in minute :)
//        public IEnumerable<Guid> WhoVoted { get; set; }

        public static Recipe Create(Guid userId, string name, string content, RecipeStatusType status, int preparationTime,
                                    int nrPeopleQuant, KitchenType cuisine)
        {
            var instance = new Recipe {
                Id = Guid.NewGuid(), UserId = userId
            };

            instance.Update(name, content, preparationTime, status, cuisine, nrPeopleQuant);
            return(instance);
        }
예제 #3
0
        public IHttpActionResult GetKitchenType(int id)
        {
            KitchenType kitchenType = db.KitchenTypes.Find(id);

            if (kitchenType == null)
            {
                return(NotFound());
            }

            return(Ok(kitchenType));
        }
예제 #4
0
 public void Update(string name, string content, int preparationTime, RecipeStatusType status, KitchenType cuisine, int nrPeopleQuantity)
 {
     Content          = content;
     PreparationTime  = preparationTime;
     Name             = name;
     Cuisine          = cuisine;
     NrPeopleQuantity = nrPeopleQuantity;
     Cost             = 0;
     Status           = status;
     Rating           = 0;
     VotesNumber      = 0;
 }
예제 #5
0
        public IHttpActionResult PostKitchenType(KitchenType kitchenType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.KitchenTypes.Add(kitchenType);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = kitchenType.KitchenTypeID }, kitchenType));
        }
예제 #6
0
        public IHttpActionResult DeleteKitchenType(int id)
        {
            KitchenType kitchenType = db.KitchenTypes.Find(id);

            if (kitchenType == null)
            {
                return(NotFound());
            }

            db.KitchenTypes.Remove(kitchenType);
            db.SaveChanges();

            return(Ok(kitchenType));
        }
예제 #7
0
 public async Task <IEnumerable <Recipe> > GetByKitchenType(KitchenType cuisine, Task <IEnumerable <Recipe> > recipes)
 {
     return((await recipes).Where(recipe =>
                                  recipe.Cuisine == cuisine));
 }