Пример #1
0
        public IActionResult PutPlaygroundPrice(int Id, PlaygroundPrice NewPlaygroundPrice)
        {
            List <PlaygroundPrice> ConflictedPrices = _playgroundPriceRepository.GetConflictedList(NewPlaygroundPrice);

            if (ConflictedPrices.Count > 0)
            {
                if (ConflictedPrices.Count == 1)
                {
                    if (ConflictedPrices[0].Id != Id)
                    {
                        return(Conflict());
                    }
                }
                else
                {
                    return(Conflict());
                }
            }
            bool result = _playgroundPriceRepository.UpdatePlaygroundPrice(Id, NewPlaygroundPrice);

            if (result == true)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        public List <PlaygroundPrice> GetConflictedList(PlaygroundPrice newPlaygroundPrice)
        {
            List <PlaygroundPrice> prices = _applicationDbContext.playgroundPrices.Where(playgroundPrice =>
                                                                                         ((((playgroundPrice.Start < newPlaygroundPrice.Start) && (playgroundPrice.End > newPlaygroundPrice.Start)) ||
                                                                                           ((playgroundPrice.Start < newPlaygroundPrice.End) && (playgroundPrice.End > newPlaygroundPrice.End)) ||
                                                                                           ((playgroundPrice.Start >= newPlaygroundPrice.Start) && (playgroundPrice.End <= newPlaygroundPrice.End))
                                                                                           ) && (playgroundPrice.PlaygroundId == newPlaygroundPrice.PlaygroundId))).ToList();

            return(prices);
        }
Пример #3
0
        public IActionResult AddPlaygroundPrice(int Id, PlaygroundPrice NewPlaygroundPrice)
        {
            List <PlaygroundPrice> ConflictedPrices = _playgroundPriceRepository.GetConflictedList(NewPlaygroundPrice);

            if (ConflictedPrices.Count > 0)
            {
                return(Conflict());
            }
            int result = _playgroundPriceRepository.AddPlaygroundPrice(NewPlaygroundPrice);

            return(Ok(new { id = result }));
        }
        public bool DeletePlaygroundPrice(int id)
        {
            PlaygroundPrice FoundplaygroundPrice = _applicationDbContext.playgroundPrices.Find(id);

            if (FoundplaygroundPrice != null)
            {
                _applicationDbContext.playgroundPrices.Remove(FoundplaygroundPrice);
                _applicationDbContext.SaveChanges();

                return(true);
            }
            return(false);
        }
        public bool UpdatePlaygroundPrice(int Id, PlaygroundPrice newPlaygroundPrice)
        {
            PlaygroundPrice FoundplaygroundPrice = SearchPlaygroundPrice(Id);

            if (FoundplaygroundPrice != null)
            {
                FoundplaygroundPrice.Price = newPlaygroundPrice.Price;
                FoundplaygroundPrice.Start = newPlaygroundPrice.Start;
                FoundplaygroundPrice.End   = newPlaygroundPrice.End;

                _applicationDbContext.Entry(FoundplaygroundPrice).State = EntityState.Modified;
                _applicationDbContext.SaveChanges();
                return(true);
            }
            return(false);
        }
        public int AddPlaygroundPrice(PlaygroundPrice NewPlaygroundPrice)
        {
            //PlaygroundPrice FoundplaygroundPrice = SearchPlaygroundPrice(NewPlaygroundPrice);
            //if (FoundplaygroundPrice == null)
            //{
            //try
            //{
            _applicationDbContext.playgroundPrices.Add(NewPlaygroundPrice);
            _applicationDbContext.SaveChanges();
            return(NewPlaygroundPrice.Id);

            //}
            //catch (Exception)
            //{
            //    return false;
            //}


            //}
            //else
            //{
            //    return false;
            //}
        }