public ActionResult <BaseResponse> Update(ProductCategory request) { var response = new BaseResponse(); try { CheckingCategoryName(request); var category = _dacProductCategory.Single(request.Id); if (category.Name != request.Name) { category.Name = request.Name; } _dacProductCategory.Update(category); _dacProductCategory.Commit(); response.Status.SetSuccess(); } catch (Exception e) { response.Status.SetError(e); } return(response); }
public ActionResult <CollectionResponse <Product> > Get(string id) { var response = new CollectionResponse <Product>(); try { var products = (string.IsNullOrEmpty(id) ? _dacProduct.All() : new[] { _dacProduct.Single(id) }) .ToList(); response.Collections = products .Select(p => new Product { Id = p.Id, Name = p.Name, Price = p.Price, Images = _dacProductImage .Where(pi => pi.ProductId.Equals(p.Id)) .Select(pi => pi.Url) .ToList(), CategoryName = _dacProductCategory.Single(p.CategoryId)? .Name ?? string.Empty }) .ToList(); response.Status.SetSuccess(); } catch (Exception e) { Console.WriteLine(e); response.Status.SetError(e); } return(response); }