public ServiceResult AddVoyage(VoyageDTO voyageDto) { var result = new ServiceResult(); if (voyageDto.EndPoint == null) result.Errors.Add(new PropertyMessagePair { PropertyName = "EndPoint", Message = "Voyage gotta have some end point" }); if (voyageDto.StartPoint == null) result.Errors.Add(new PropertyMessagePair { PropertyName = "StartPoint", Message = "Voyage gotta have some start point" }); if (voyageDto.StartPoint == null || voyageDto.EndPoint == null) return result; voyageDto.Status = DTO.VoyageStatus.Open; voyageDto.LifeCycle = new VoyageLifeCycleDTO { Opened = DateTime.Now }; try { _db.Voyages.Create(Mapper.Map<Voyage>(voyageDto)); _db.Save(); } catch (DbEntityValidationException ex) { result.Append(ex); } return result; }
public ServiceResult ModifyVoyage(VoyageDTO voyageDto) { var result = new ServiceResult(); var voyage = _db.Voyages.Get(voyageDto.Id); if (voyage == null) { result.Errors.Add(new PropertyMessagePair { PropertyName = "Id", Message = "There is no such voyage in db you wanna modify" }); return result; } if (voyage.Status == VoyageStatus.Processing) { result.Errors.Add(new PropertyMessagePair { PropertyName = "voyageDto", Message = "You can't modify voyage while it's processing" }); return result; } if (voyage.Status == VoyageStatus.Accepted) { result.Errors.Add(new PropertyMessagePair { PropertyName = "voyageDto", Message = "You can't modify voyage after accepting" }); return result; } if (voyage.Status == VoyageStatus.Succeded) { result.Errors.Add(new PropertyMessagePair { PropertyName = "voyageDto", Message = "You can't modify voyage after it's succeded" }); return result; } try { _db.Voyages.Update(Mapper.Map<Voyage>(voyageDto)); _db.Save(); } catch (DbEntityValidationException ex) { result.Append(ex); } return result; }