Exemplo n.º 1
0
 /// <summary>
 /// Maps: Id, Name
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 /// <exception cref="NullReferenceException"></exception>
 public static BLLProductDTO FromDAL3(DALProductDTO dto)
 {
     if (dto == null)
     {
         throw new NullReferenceException("Can't map, DALProductDTO is null");
     }
     return(new BLLProductDTO()
     {
         Id = dto.Id,
         ProductName = dto.Name
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// Only use when mapping new product
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 public static Product FromDAL(DALProductDTO dto)
 {
     if (dto == null)
     {
         throw new NullReferenceException("Can't use Mapper on a null object");
     }
     return(new Product()
     {
         OrganizationId = dto.OrganizationId,
         ProductName = new MultiLangString(dto.Name),
         ProductDescription = new MultiLangString(dto.Description)
     });
 }
Exemplo n.º 3
0
 /// <summary>
 /// Maps: Id, Price, Name, Description, OrganizationId
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 /// <exception cref="NullReferenceException"></exception>
 public static BLLProductDTO FromDAL2(DALProductDTO dto)
 {
     if (dto == null)
     {
         throw new NullReferenceException("Can't map, DALProductDTO is null");
     }
     return(new BLLProductDTO()
     {
         Id = dto.Id,
         CurrentPrice = dto.CurrentPrice,
         ProductName = dto.Name,
         Description = dto.Description,
         OrganizationId = dto.OrganizationId,
     });
 }
Exemplo n.º 4
0
 /// <summary>
 /// Maps: Id, Price, Name, Description, OrganizationId, CategoriesMin
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 /// <exception cref="NullReferenceException"></exception>
 public static BLLProductDTO FromDAL(DALProductDTO dto)
 {
     if (dto == null)
     {
         throw new NullReferenceException("Can't map, DALProductDTO is null");
     }
     return(new BLLProductDTO()
     {
         Id = dto.Id,
         CurrentPrice = dto.CurrentPrice,
         ProductName = dto.Name,
         Description = dto.Description,
         OrganizationId = dto.OrganizationId,
         Categories = dto.Categories
                      .Select(CategoryMapper.FromDALToMin)
                      .ToList()
     });
 }
        public async Task <DALProductDTO> AddAsync(DALProductDTO dto)
        {
            var product = ProductMapper.FromDAL(dto);

            product = (await RepoDbSet.AddAsync(product)).Entity;
            if (product == null)
            {
                return(null);
            }
            await RepoDbContext.Entry(product).Reference(p => p.ProductName).LoadAsync();

            await RepoDbContext.Entry(product.ProductName).Collection(name => name.Translations).LoadAsync();

            await RepoDbContext.Entry(product).Reference(p => p.ProductDescription).LoadAsync();

            await RepoDbContext.Entry(product.ProductDescription).Collection(desc => desc.Translations).LoadAsync();


            return(ProductMapper.FromDomain(product));
        }
        /// <summary>
        /// Edits products name and description, then returns productDTO
        /// </summary>
        /// <param name="dalProductDTO"></param>
        /// <returns></returns>
        public async Task <DALProductDTO> EditAsync(DALProductDTO dalProductDTO)
        {
            var product = await RepoDbSet.FindAsync(dalProductDTO.Id);

            if (product == null)
            {
                return(null);
            }
            await RepoDbContext.Entry(product).Reference(p => p.ProductName).LoadAsync();

            await RepoDbContext.Entry(product.ProductName).Collection(name => name.Translations).LoadAsync();

            await RepoDbContext.Entry(product).Reference(p => p.ProductDescription).LoadAsync();

            await RepoDbContext.Entry(product.ProductDescription).Collection(desc => desc.Translations).LoadAsync();

            product.ProductDescription.SetTranslation(dalProductDTO.Description);
            product.ProductName.SetTranslation(dalProductDTO.Name);

            return(ProductMapper.FromDomain(product));
        }