public ResultDto InsertProduct(ProductPost post) { ResultDto result = new ResultDto(); //判断该产品是否已添加 var builder = Builders<ProductMongo>.Filter; var filter = builder.Eq(x => x.Name, post.name); filter &= builder.Eq(x => x.IsDel, false); var col = MongoDBHelper.Instance.GetProduct(); try { var query = col.Find(filter).FirstOrDefault(); if (query != null) { result.Message = "该产品已存在!"; return result; } var product = new ProductMongo { Name = post.name, Description = post.description, Price = post.price, CreatedAt = DateTime.Now.AddHours(8), }; col.InsertOne(product); result.IsSuccess = true; return result; } catch (Exception ex) { result.Message = ex.Message; return result; } }
public Product(ProductMongo mongoProduct, Uom uom, Currency currency) { Active = mongoProduct._active; Code = mongoProduct.code; CurrencyCode = mongoProduct.currency.code; Description = mongoProduct.description; Name = mongoProduct.name; Price = mongoProduct.price; Tags = mongoProduct.tags; UId = mongoProduct._id.ToString(); _CreatedAgent = mongoProduct._createAgent; _CreatedBy = mongoProduct._createdBy; _CreatedUtc = mongoProduct._createdDate; UomId = uom != null ? uom.Id : 0; UomUnit = uom != null ? uom.Unit : ""; CurrencyId = currency != null ? currency.Id : 0; CurrencyCode = currency != null ? currency.Code : ""; CurrencySymbol = currency != null ? currency.Symbol : ""; _DeletedAgent = mongoProduct._updateAgent; _DeletedBy = mongoProduct._updatedBy; _DeletedUtc = mongoProduct._updatedDate; _IsDeleted = mongoProduct._deleted; _LastModifiedAgent = mongoProduct._updateAgent; _LastModifiedBy = mongoProduct._updatedBy; _LastModifiedUtc = mongoProduct._updatedDate; }
public ProductSPPProperty(ProductMongo mongoProduct) { Active = mongoProduct._active; _CreatedAgent = mongoProduct._createAgent; _CreatedBy = mongoProduct._createdBy; _CreatedUtc = mongoProduct._createdDate; _DeletedAgent = mongoProduct._updateAgent; _DeletedBy = mongoProduct._updatedBy; _DeletedUtc = mongoProduct._updatedDate; _IsDeleted = mongoProduct._deleted; _LastModifiedAgent = mongoProduct._updateAgent; _LastModifiedBy = mongoProduct._updatedBy; _LastModifiedUtc = mongoProduct._updatedDate; }
public ProductMongoTests() { sut = CreateProductMongo(); }