コード例 #1
0
 public async Task <IActionResult> Delete([FromBody] ExcursionGroup excursionGroupId)
 {
     try
     {
         var excursionGroup = _context.ExcursionGroups.FirstOrDefault(x => x.Id == excursionGroupId.Id);
         if (excursionGroup != null)
         {
             _logger.LogInformation("Try to delete excursionGroup: {0}", excursionGroup.Id);
             _context.ExcursionGroups.Remove(excursionGroup);
         }
         await _context.SaveChangesAsync();
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
         return(BadRequest(e.Message));
     }
     _logger.LogInformation("ExcursionGroup was deleted by user: {0}", User.Identity.Name);
     return(Ok("Excursion group was deleted successfully"));
 }
コード例 #2
0
        public async Task <IActionResult> Update([FromBody] ExcursionGroup excursionGroupid)
        {
            try
            {
                var excursionGroup = _context.ExcursionGroups.FirstOrDefault(x => x.Id == excursionGroupid.Id);
                if (excursionGroup != null)
                {
                    var currentCapacity = _context.GetExcursionGroupsCapacity(excursionGroup.ExcursionId);
                    //TODO: this shit dont work- excursion.Tour.Capacity
                    var a = _context.Tours.FirstOrDefault(x => x.Id == _context.Excursions.FirstOrDefault(e => e.Id == excursionGroup.ExcursionId).Id);
                    if (a != null && a.Capacity >= (currentCapacity + excursionGroup.GetCapacity(_context)))
                    {
                        _context.ExcursionGroups.Update(excursionGroup);
                        _logger.LogInformation("Try to update excursionGroup");

                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        _logger.LogWarning("Not enough excursion space. Current workload is: {0} / {1}",
                                           currentCapacity, a.Capacity);
                        return(BadRequest("Not enough excursion space"));
                    }

                    _logger.LogWarning("Try to update excursion group {0}", excursionGroup.Id);
                    _context.ExcursionGroups.Update(excursionGroup);
                }

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(BadRequest(e.Message));
            }

            _logger.LogWarning("ExcursionGroup was updated by user {0}", User.Identity.Name);
            return(Ok("Excursion group was updated successfully"));
        }
コード例 #3
0
        public async Task <IActionResult> Add([FromBody] ExcursionGroup excursionGroup)
        {
            try
            {
                var excursion = _context.Excursions.FirstOrDefault(x => x.Id == excursionGroup.ExcursionId);
                if (excursion != null && excursion.Status)
                {
                    var currentCapacity = _context.GetExcursionGroupsCapacity(excursionGroup.ExcursionId);
                    //TODO: this shit dont work- excursion.Tour.Capacity
                    var a = _context.Tours.FirstOrDefault(x => x.Id == excursion.TourId);

                    if (a != null && a.Capacity >= (currentCapacity + excursionGroup.GetCapacity(_context)))
                    {
                        _context.ExcursionGroups.Add(excursionGroup);
                        _logger.LogInformation("Try to add new excursionGroup");

                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        _logger.LogWarning("Not enough excursion space. Current workload is: {0} / {1}",
                                           currentCapacity, a.Capacity);
                        return(BadRequest("Not enough excursion space"));
                    }
                }
                else
                {
                    _logger.LogError("Incorrect data for excursion groups from user: {0}", User.Identity.Name);
                    return(BadRequest("Incorrect data"));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(BadRequest(e.Message));
            }
            _logger.LogInformation("ExcursionGroup was added by user: {0}", User.Identity.Name);
            return(Ok("Excursion group was added to excursion successfully"));
        }