Exemplo n.º 1
0
        public HttpResponseMessage AddCodeJewel([FromBody] CodeJewel code)
        {
            var response = PerformOperation(() =>
            {
                var context = new CodeJewelEntities();
                using (context)
                {
                    context.CodeJewels.Add(code);
                    context.SaveChanges();
                    CodeJewelModel model = DesirializeCodeJewel(code);
                    return(model);
                }
            });

            return(response);
        }
Exemplo n.º 2
0
        public HttpResponseMessage AddVote(int id, [FromBody] Vote vote)
        {
            var response = PerformOperation(() =>
            {
                var context = new CodeJewelEntities();
                using (context)
                {
                    var jewel = context.CodeJewels.FirstOrDefault(j => j.Id == id);
                    if (jewel == null)
                    {
                        throw new InvalidOperationException("The jewel does not exists!");
                    }
                    jewel.Votes.Add(vote);
                    context.Votes.Add(vote);
                    context.SaveChanges();

                    return(vote);
                }
            });

            return(response);
        }