Beispiel #1
0
        public IHttpActionResult PostPricelist(TicketPricesHelpModel t)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (t.Hourly <= 0 || t.Daily <= 0 || t.Monthly <= 0 || t.Yearly <= 0)
            {
                return(Content(HttpStatusCode.BadRequest, "Invalid value for prices."));
            }
            if (t.PriceList.StartOfValidity.ToString() == "" || t.PriceList.EndOfValidity.ToString() == "")
            {
                return(Content(HttpStatusCode.BadRequest, "Invalid dates for validity period. Dates can't be empty."));
            }
            if (t.PriceList.StartOfValidity > t.PriceList.EndOfValidity)
            {
                return(Content(HttpStatusCode.BadRequest, "Invalid dates for validity period. Start of validity period is greater than the end."));
            }
            if (t.PriceList.StartOfValidity.Value.Date < DateTime.Now.Date)
            {
                return(Content(HttpStatusCode.BadRequest, "Invalid dates for validity period. Start of validity period can't be older than today."));
            }
            try
            {
                Pricelist prl = new Pricelist();
                prl = t.PriceList;
                prl.TicketPricess = new List <TicketPrices>();
                TicketPrices tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Hourly").FirstOrDefault().Id;

                tp.Price = t.Hourly;

                prl.TicketPricess.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Daily").FirstOrDefault().Id;
                //tp.PricelistId = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price = t.Daily;
                prl.TicketPricess.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Monthly").FirstOrDefault().Id;
                //tp.PricelistId = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price = t.Monthly;
                prl.TicketPricess.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Yearly").FirstOrDefault().Id;
                //tp.PricelistId = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price = t.Yearly;
                prl.TicketPricess.Add(tp);

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

                return(Ok());
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
        public TicketPricesHelpModel GetValidPrices(int id)
        {
            TicketPricesHelpModel tp = new TicketPricesHelpModel();
            var p = unitOfWork.TicketPrices.Find(x => x.PricelistId == id);

            TicketType tt = unitOfWork.TicketTypes.Find(m => m.Name == "Daily").FirstOrDefault();

            tp.Daily       = (int)p.First(x => x.TicketTypeId == tt.Id).Price;
            tt             = unitOfWork.TicketTypes.Find(m => m.Name == "Monthly").FirstOrDefault();
            tp.Monthly     = (int)p.First(x => x.TicketTypeId == tt.Id).Price;
            tt             = unitOfWork.TicketTypes.Find(m => m.Name == "Yearly").FirstOrDefault();
            tp.Yearly      = (int)p.First(x => x.TicketTypeId == tt.Id).Price;
            tt             = unitOfWork.TicketTypes.Find(m => m.Name == "Hourly").FirstOrDefault();
            tp.Hourly      = (int)p.First(x => x.TicketTypeId == tt.Id).Price;
            tp.IdPriceList = id;

            return(tp);
        }
        public IHttpActionResult PostTicketPrices([FromBody] TicketPricesHelpModel hm)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            try
            {
                TicketPrices tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Hourly").FirstOrDefault().Id;
                tp.PricelistId  = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price        = hm.Hourly;

                unitOfWork.TicketPrices.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Daily").FirstOrDefault().Id;
                tp.PricelistId  = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price        = hm.Daily;
                unitOfWork.TicketPrices.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Monthly").FirstOrDefault().Id;
                tp.PricelistId  = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price        = hm.Monthly;
                unitOfWork.TicketPrices.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Yearly").FirstOrDefault().Id;
                tp.PricelistId  = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price        = hm.Yearly;

                unitOfWork.TicketPrices.Add(tp);

                unitOfWork.Complete();
                return(Ok());
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Beispiel #4
0
        public IHttpActionResult PostPricelist(TicketPricesHelpModel t)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //validacije
            if (t.Hourly <= 0 || t.Daily <= 0 || t.Monthly <= 0 || t.Yearly <= 0)
            {
                return(Content(HttpStatusCode.BadRequest, "Prices can't be less then 1!"));
            }
            if (t.PriceList.StartOfValidity.ToString() == "" || t.PriceList.EndOfValidity.ToString() == "" || t.PriceList.StartOfValidity == null || t.PriceList.EndOfValidity == null)
            {
                return(Content(HttpStatusCode.BadRequest, "Start or end of validity can't be empty!"));
            }
            if (t.PriceList.StartOfValidity.Value.Date < DateTime.Now.Date)
            {
                return(Content(HttpStatusCode.BadRequest, "You can't make pricelist for past!"));
            }

            if (t.PriceList.StartOfValidity > t.PriceList.EndOfValidity)
            {
                return(Content(HttpStatusCode.BadRequest, "Start of validity is bigger then end of validity!"));
            }

            try
            {
                Pricelist prl = new Pricelist();
                prl = t.PriceList;
                prl.TicketPricess = new List <TicketPrices>();
                TicketPrices tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Hourly").FirstOrDefault().Id;

                tp.Price = t.Hourly;

                prl.TicketPricess.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Daily").FirstOrDefault().Id;
                //tp.PricelistId = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price = t.Daily;
                prl.TicketPricess.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Monthly").FirstOrDefault().Id;
                //tp.PricelistId = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price = t.Monthly;
                prl.TicketPricess.Add(tp);
                tp = new TicketPrices();
                tp.TicketTypeId = unitOfWork.TicketTypes.Find(k => k.Name == "Yearly").FirstOrDefault().Id;
                //tp.PricelistId = unitOfWork.PriceLists.Get(hm.IdPriceList).Id;
                tp.Price = t.Yearly;
                prl.TicketPricess.Add(tp);

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

                return(Ok());
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }