/// <summary> /// Add method. /// </summary> /// <param name="dto"></param> /// <returns></returns> public Product Save(Product dto) { Product update = dto.Id > 0 ? productDAC.FindById <Product>(dto.Id) : new Product { CreatedOn = DateTime.Now }; update.Description = string.IsNullOrEmpty(dto.Description) ? throw new BusinessException("b.validation.product.description.invalid") : dto.Description; update.Image = string.IsNullOrEmpty(dto.Image) ? throw new BusinessException("b.validation.product.image.invalid") : dto.Image; update.Price = dto.Price < 0 ? throw new BusinessException("b.validation.product.price.invalid") : dto.Price; update.Title = string.IsNullOrEmpty(dto.Title) ? throw new BusinessException("b.validation.product.title.invalid") : dto.Title; update.Rowid = dto.Rowid == null || dto.Rowid == Guid.Empty ? Guid.NewGuid() : dto.Rowid; if (dto.DealerId <= 0 || dealerBusiness.Find(dto.DealerId) == null) { throw new BusinessException("b.validation.product.dealer.invalid"); } else { update.DealerId = dto.DealerId; } update.ChangedOn = DateTime.Now; var saved = productDAC.Save(update); return(saved); }