Esempio n. 1
0
        public async Task <Response <IPriceListDTO> > GetAllPrices()
        {
            var response = new Response <IPriceListDTO>();

            var priceList = await _db.MenuItems.ToListAsync();

            if (priceList.ToArray().Length == 0)
            {
                response.Error = new Error(404, "Price list not found");
                return(response);
            }

            var data = new PriceListDTO(priceList);

            response.Data = data;
            return(response);
        }
Esempio n. 2
0
        // POST api/pricelists
        public HttpResponseMessage CreatePriceList([FromBody] PriceListDTO priceListDTO)
        {
            PriceList newPriceList = new PriceList();

            newPriceList.StartDate   = priceListDTO.StartDate;
            newPriceList.EndDate     = priceListDTO.EndDate;
            newPriceList.TicketTypes = priceListDTO.TicketTypes;
            newPriceList.Tickets     = priceListDTO.Tickets;


            unitOfWork.PriceLists.Add(newPriceList);
            unitOfWork.Complete();

            var message = Request.CreateResponse(HttpStatusCode.Created, newPriceList);

            message.Headers.Location = new Uri(Request.RequestUri + "/" + newPriceList.Id.ToString());

            return(message);
        }
Esempio n. 3
0
        // PUT api/pricelists/5
        public HttpResponseMessage UpdatePriceList(int id, [FromBody] PriceListDTO priceListDTO)
        {
            var priceListToBeUpdated = unitOfWork.PriceLists.GetAll().Where(x => x.Id == id && x.Deleted == false).SingleOrDefault();

            priceListToBeUpdated.TicketTypes[0].Price = priceListDTO.TicketTypes[0].Price;
            priceListToBeUpdated.TicketTypes[1].Price = priceListDTO.TicketTypes[1].Price;
            priceListToBeUpdated.TicketTypes[2].Price = priceListDTO.TicketTypes[2].Price;
            priceListToBeUpdated.TicketTypes[3].Price = priceListDTO.TicketTypes[3].Price;
            priceListToBeUpdated.StartDate            = priceListDTO.StartDate;
            priceListToBeUpdated.EndDate = priceListDTO.EndDate;

            if (priceListToBeUpdated != null)
            {
                unitOfWork.PriceLists.Update(priceListToBeUpdated);
                unitOfWork.Complete();

                return(Request.CreateResponse(HttpStatusCode.OK, priceListToBeUpdated));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PriceList with that id number doesn't exist."));
            }
        }