コード例 #1
0
        public async Task <UrgencyResponse> UpdateAsync(int guardianId, int urgencyId, Urgency urgency)
        {
            var existingGuardian = await _guardianRepository.FindByIdAsync(guardianId);

            if (existingGuardian == null)
            {
                return(new UrgencyResponse("Guardian not found"));
            }

            var existingUrgency = await _urgencyRepository.FindByIdAsync(urgencyId);

            if (existingUrgency == null)
            {
                return(new UrgencyResponse("Urgency not found"));
            }

            existingUrgency.Title     = urgency.Title;
            existingUrgency.Summary   = urgency.Summary;
            existingUrgency.Latitude  = urgency.Latitude;
            existingUrgency.Longitude = urgency.Longitude;

            var othersUrgencies = await _urgencyRepository.ListByGuardianIdAsync(guardianId);


            var otherUrgency = othersUrgencies.Where(other => other != existingUrgency).Where(other => existingUrgency.Title == other.Title && existingUrgency.Latitude == other.Latitude &&
                                                                                              existingUrgency.Longitude == other.Longitude && existingUrgency.ReportedAt.Date == other.ReportedAt.Date).ToList().FirstOrDefault();

            if (otherUrgency != null)
            {
                return(new UrgencyResponse("There is another urgency with same title, location and report day"));
            }

            try
            {
                _urgencyRepository.Update(existingUrgency);
                await _unitOfWork.CompleteAsync();

                return(new UrgencyResponse(urgency));
            }
            catch (Exception ex)
            {
                return(new UrgencyResponse($"An error ocurred while updating the urgency: {ex.Message}"));
            }
        }
コード例 #2
0
 public void Update(UrgencyEntity item)
 {
     _urgencyRep.Update(item);
 }