public async Task <IManagerActionResultModel <Size> > UpdateProductSizeAsync(IUpdateSizeModel model) { var result = new ManagerActionResultModel <Size>(); try { Size entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Size not found!")); } entity.Name = model.Name; await this.sizeRepo.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); }
public async Task <IManagerActionResultModel <ProductColor> > CreateProductColorAsync(ICreateColorModel model) { var result = new ManagerActionResultModel <ProductColor>(); try { var entity = new ProductColor() { Name = model.Name, Value = model.Value }; this.colorRepo.Add(entity); await this.colorRepo.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); }
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 <Category> > UpdateProductCategoryTranslation(ITranslationCategoryModel model) { var result = new ManagerActionResultModel <Category>(); Category entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Category not found!")); } if (model.Language == this.appSettings.DefaultLanguage) { return(await UpdateProductCategoryAsync(model)); } else { CategoryTranslation translation = entity.Translations.Where(t => t.Language == model.Language).FirstOrDefault(); if (translation == null) { translation = new CategoryTranslation() { Category = entity, CategoryId = entity.Id, Language = model.Language }; entity.Translations.Add(translation); } translation.Name = model.Name; await this.categoryRepo.SaveAsync(); } return(result); }
public async Task <IManagerActionResultModel <Category> > UpdateProductCategoryAsync(IUpdateCategoryModel model) { var result = new ManagerActionResultModel <Category>(); try { Category entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Category not found!")); } CategoryTranslation translation = entity.Translations.Where(t => t.Language == this.appSettings.DefaultLanguage).FirstOrDefault(); entity.Name = model.Name; translation.Name = model.Name; await this.categoryRepo.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); }
public async Task <IManagerActionResultModel <Vlog> > CreateVlogAsync(ICreateVlogModel model) { var result = new ManagerActionResultModel <Vlog>(); try { string alias = model.Alias.ToLowerInvariant(); bool isExisting = this.repository.All().Where(v => v.Alias == alias).Any(); if (isExisting) { result.Errors.Add(new ErrorResultModel() { Code = nameof(model.Name), Message = $"Vlog with alias {model.Alias} already exists!" }); return(result); } var entity = new Vlog() { Alias = alias, Name = model.Name, EmbededVideo = model.EmbededVideo, ThumbnailId = model.ThumbImageId }; entity.Translations.Add(new VlogTranslation() { Vlog = entity, Language = this.settings.DefaultLanguage, Name = model.Name }); await this.repository.AddAsync(entity); 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); }
public async Task <IManagerActionResultModel <Category> > CreateProductCategoryAsync(ICreateCategoryModel model) { var result = new ManagerActionResultModel <Category>(); try { bool isExisting = this.categoryRepo.All().Where(c => c.Name == model.Name).Any(); if (isExisting) { result.Errors.Add(new ErrorResultModel() { Code = nameof(model.Name), Message = $"Category with name {model.Name} already exists!" }); return(result); } var entity = new Category() { Name = model.Name }; entity.Translations.Add(new CategoryTranslation() { Category = entity, Language = this.appSettings.DefaultLanguage, Name = model.Name }); this.categoryRepo.Add(entity); await this.categoryRepo.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); }
public async Task <IManagerActionResultModel <Size> > CreateProductSizeAsync(ICreateSizeModel model) { var result = new ManagerActionResultModel <Size>(); try { bool isExisting = this.sizeRepo.All().Where(c => c.Name == model.Name).Any(); if (isExisting) { result.Errors.Add(new ErrorResultModel() { Code = nameof(model.Name), Message = $"Size with name {model.Name} already exists!" }); return(result); } var entity = new Size() { Name = model.Name }; this.sizeRepo.Add(entity); await this.sizeRepo.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); }
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); }
public async Task <IManagerActionResultModel <Product> > CreateProductAsync(ICreateProductModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var result = new ManagerActionResultModel <Product>(); result.Succeeded = true; try { var brand = await this.brandRepo.GetByIdAsync(model.BrandId); if (brand == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(nameof(model.BrandId), "Brand not found!")); } var color = await this.colorRepo.GetByIdAsync(model.ColorId); if (color == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(nameof(model.ColorId), "Color not found!")); } var mainImage = await this.imageRepo.GetByIdAsync(model.MainImageId); if (mainImage == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(nameof(model.MainImageId), "Main image not found!")); } var hilightImage = model.HighlightImageId != null ? await this.imageRepo.GetByIdAsync(model.HighlightImageId) : mainImage; if (hilightImage == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(nameof(model.HighlightImageId), "Highlight image not found!")); } if (result.Succeeded) { var product = new Product() { Alias = model.Alias, Brand = brand, BrandId = model.BrandId, Color = color, ColorId = model.ColorId, Description = model.Description, Price = model.Price, MainImage = mainImage, MainImageId = model.MainImageId, HighlightImage = hilightImage, Name = model.Name, SKUCode = model.SKUCode, TargetType = model.TargetType, Status = ProductStatus.Draft }; if (model.SizeIds != null) { var sizes = this.sizeRepo.GetRange(model.SizeIds).ToList(); await AddSizesToProduct(product, sizes); } if (model.CategoryIds != null) { var categories = this.categoryRepo.GetRange(model.CategoryIds).ToList(); await AddCategoriesToProduct(product, categories); } if (model.GalleryImageIds != null) { var images = this.imageRepo.GetRange(model.GalleryImageIds).ToList(); await AddImagesToProduct(product, images); } await this.repository.AddAsync(product); await this.repository.SaveAsync(); result.Model = product; } } catch (Exception ex) { result.Errors = new List <IErrorResultModel>() { new ErrorResultModel(ex) }; result.Succeeded = false; if (ex.InnerException != null) { result.Errors.Add(new ErrorResultModel(ex.InnerException)); } } return(result); }