public static Model.TroubleCreationInfo Convert(Client.TroubleCreationInfo creationInfo, IReadOnlyList <Models.Tags.Tag> modelTags) { if (creationInfo == null) { throw new ArgumentNullException(nameof(creationInfo)); } if (modelTags == null) { throw new ArgumentNullException(nameof(modelTags)); } var filteredTagIds = TroubleConverterUtils.FilterWrongTagIds(creationInfo.Tags, modelTags).ToArray(); if (filteredTagIds == null || !filteredTagIds.Any()) { throw new InvalidDataException($"{nameof(filteredTagIds)} can't be empty."); } var coordinates = creationInfo.Coordinates.ToArray(); if (coordinates.Length != CoordinatesLength) { throw new InvalidDataException(nameof(creationInfo.Coordinates)); } var modelCreationInfo = new Model.TroubleCreationInfo(creationInfo.Name, creationInfo.Description, coordinates[0], coordinates[1], creationInfo.Address, filteredTagIds); return(modelCreationInfo); }
public static Model.TroublePatchInfo Convert(string id, Client.TroublePatchInfo clientPatchInfo, IReadOnlyList <Models.Tags.Tag> modelTags) { if (clientPatchInfo == null) { throw new ArgumentNullException(nameof(clientPatchInfo)); } if (modelTags == null) { throw new ArgumentNullException(nameof(modelTags)); } string[] filteredTagIds = null; if (clientPatchInfo.Tags != null) { filteredTagIds = TroubleConverterUtils.FilterWrongTagIds(clientPatchInfo.Tags, modelTags).ToArray(); if (!filteredTagIds.Any()) { throw new InvalidDataException($"{nameof(filteredTagIds)} can't be empty."); } } double?latitude = null, longitude = null; if (clientPatchInfo.Coordinates != null) { if (clientPatchInfo.Coordinates.Count != CoordinatesLength) { throw new InvalidDataException( $"{nameof(clientPatchInfo.Coordinates)} must contain 2 values (lat and long)."); } latitude = clientPatchInfo.Coordinates[0]; longitude = clientPatchInfo.Coordinates[1]; } var guid = TroubleConverterUtils.ConvertId(id); var status = TroubleConverterUtils.ConvertStatus(clientPatchInfo.Status); var modelPathInfo = new Models.Troubles.TroublePatchInfo(guid) { Name = clientPatchInfo.Name, Description = clientPatchInfo.Description, Images = clientPatchInfo.Images, Latitude = latitude, Longitude = longitude, Address = clientPatchInfo.Address, Tags = filteredTagIds, Status = status }; return(modelPathInfo); }