Ejemplo n.º 1
0
        protected StringContent BaseRequest(PriceDeserializer priceDsl, string email)
        {
            var admin = Context.User.Include(e => e.Role).FirstOrDefault(e => e.Email == email);

            var newContent = new StringContent(
                JsonConvert.SerializeObject(priceDsl),
                Encoding.UTF8,
                "application/json"
                );

            HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
                                                                                           TokenBearerHelper.GetTokenFor(admin, Context));

            return(newContent);
        }
Ejemplo n.º 2
0
        public IActionResult Create([FromBody] PriceDeserializer priceDsl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool mPrice = Context.Price.Any(p => p.EventId == priceDsl.EventId && p.RoleId == priceDsl.RoleId);
            bool mEvent = Context.Event.Any(p => p.Id == priceDsl.EventId);
            bool mRole  = Context.Role.Any(p => p.Id == priceDsl.RoleId);

            if (mPrice)
            {
                return(BadRequest("Price Already exist"));
            }
            if (!mEvent)
            {
                return(BadRequest("Event doesn't exist"));
            }
            if (!mRole)
            {
                return(BadRequest("Role doesn't exist"));
            }

            var price = new Price()
            {
                EventId = priceDsl.EventId,
                RoleId  = priceDsl.RoleId,
                Amount  = priceDsl.Amount
            };

            try {
                Context.Price.Add(price);
                Context.SaveChanges();
            } catch (DbUpdateException e) {
                return(BadRequest(e.Message));
            }

            return(NoContent());
        }