private async Task SaveToDatabase() { try { await UnitOfWork.SaveChangesAsync(); } catch (DbEntityValidationException e) { foreach (var failure in e.EntityValidationErrors) { _operationLog.Error($"Validation failed: {failure.Entry.Entity} "); foreach (var error in failure.ValidationErrors) { _operationLog.Error($"- {error.PropertyName} : {error.ErrorMessage}"); } } throw; } }
public async Task <IEnumerable <string> > UpdateProject(int currentUserId, int projectId) { var project = await ProjectRepository.GetProjectAsync(projectId); project.RequestMasterAccess(currentUserId, acl => acl.IsOwner); if (project.Details?.AllrpgId == null) { return(new[] { "Проект не ассоциирован с allrpg" }); } var reply = await _api.DownloadProject((int)project.Details.AllrpgId); switch (reply.Status) { case AllrpgApi.Status.Success: { var log = new OperationLog(); try { var importer = new AllrpgProjectImporter(project, UnitOfWork, log); await importer.Apply(reply.Result); } catch (Exception e) { log.Error($"EXCEPTION: {e}"); } return(log.Results); } case AllrpgApi.Status.NetworkError: return(new[] { "Сетевая ошибка" }); case AllrpgApi.Status.ParseError: return(new[] { "Не разобран ответ allrpg" }); case AllrpgApi.Status.WrongKey: return(new[] { "Ошибочный ключ" }); default: throw new ArgumentOutOfRangeException(nameof(reply.Status)); } }