public async Task <IManagerActionResultModel <Vlog> > UpdateVlogTranslation(IUpdateTranslationVlogModel model) { var result = new ManagerActionResultModel <Vlog>(); Vlog entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Vlog not found!")); } if (model.Language == this.settings.DefaultLanguage) { model.Name = model.Name; } VlogTranslation translation = entity.Translations.Where(t => t.Language == model.Language).FirstOrDefault(); if (translation == null) { translation = new VlogTranslation() { Vlog = entity, VlogId = entity.Id, Language = model.Language }; entity.Translations.Add(translation); } translation.Name = model.Name; await this.repository.SaveAsync(); return(result); }
public async Task <IManagerActionResultModel <Vlog> > UpdateVlogAsync(IUpdateVlogModel model) { var result = new ManagerActionResultModel <Vlog>(); try { Vlog entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Vlog not found!")); } VlogTranslation translation = entity.Translations.Where(t => t.Language == this.settings.DefaultLanguage).FirstOrDefault(); entity.Name = model.Name; entity.Alias = model.Alias; entity.EmbededVideo = model.EmbededVideo; entity.ThumbnailId = model.ThumbImageId; translation.Name = model.Name; await this.repository.SaveAsync(); result.Succeeded = true; result.Model = entity; } catch (Exception ex) { result.Errors.Add(new ErrorResultModel(ex)); if (ex.InnerException != null) { result.Errors.Add(new ErrorResultModel(ex.InnerException)); } } return(result); }