Пример #1
0
        /// <summary>
        /// 从索引文档获取附近购(商家)商品
        /// </summary>
        /// <returns></returns>
        private MerchantProduct GetMerchantproduct()
        {
            var product = new MerchantProduct();

            product.DataType   = IndexDataType.MerchantProduct;
            product.AreaID     = Convert.ToInt32(_doc.Get("areaid"));
            product.AreaLayer  = _doc.Get("arealayer");
            product.CreateTime = DateTime.Parse(_doc.Get("createtime"));
            product.ID         = Convert.ToInt64(_doc.Get("id"));
            product.Name       = _doc.Get("name");
            product.Pic        = _doc.Get("pic");
            product.UpdateTime = DateTime.Parse(_doc.Get("updatetime"));

            product.OriginalPrice      = decimal.Parse(_doc.Get("originalprice"));
            product.SystemCategoryID   = Convert.ToInt64(_doc.Get("systemcategoryid"));
            product.SystemCategoryName = _doc.Get("systemcategoryname");
            product.MerchantID         = Convert.ToInt64(_doc.Get("merchantid"));
            product.MerchantName       = _doc.Get("merchantname");
            product.SalePrice          = decimal.Parse(_doc.Get("saleprice"));
            product.Specification      = _doc.Get("specification");
            product.Latitude           = float.Parse(_doc.Get("latitude"));
            product.Longitude          = float.Parse(_doc.Get("longitude"));


            return(product);
        }
Пример #2
0
        public async Task <IHttpActionResult> PutMerchantProduct(int id, MerchantProduct merchantProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != merchantProduct.merchant_product_id)
            {
                return(BadRequest());
            }

            db.Entry(merchantProduct).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MerchantProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IHttpActionResult> GetMerchantProduct(int id)
        {
            MerchantProduct merchantProduct = await db.merchant_product.FindAsync(id);

            if (merchantProduct == null)
            {
                return(NotFound());
            }

            return(Ok(merchantProduct));
        }
Пример #4
0
        public async Task <IHttpActionResult> PostMerchantProduct(MerchantProduct merchantProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.merchant_product.Add(merchantProduct);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = merchantProduct.merchant_product_id }, merchantProduct));
        }
Пример #5
0
        public async Task <bool> UpdateAsync(MerchantProduct item)
        {
            return(await Task.Run(() =>
            {
                item.DataType = Enums.IndexDataType.MerchantProduct;
                item.Pic = (item.Pic ?? string.Empty).Split(new[] { ',', '|' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
                item.Desc = string.Empty;
                item.UpdateTime = DateTime.Now;

                AreaIndexManager.Instance.Modify(item);
                MerchantProductIndexManager.Instance.Modify(item);

                return true;
            }));
        }
Пример #6
0
        public async Task <IHttpActionResult> DeleteMerchantProduct(int id)
        {
            //delete from
            MerchantProduct merchantProduct = await db.merchant_product.FindAsync(id);

            if (merchantProduct == null)
            {
                return(NotFound());
            }

            db.merchant_product.Remove(merchantProduct);
            await db.SaveChangesAsync();

            return(Ok(merchantProduct));
        }
Пример #7
0
        public async Task <IHttpActionResult> PostSoftDeleteMerchantProduct(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //MerchantProduct product = await db.merchant_product.FindAsync(id);
            MerchantProduct product = await db.merchant_product
                                      .Where(x => (x.merchant_product_id.Equals(id))).SingleOrDefaultAsync();

            if (product == null)
            {
                return(Ok("Invaild Request"));
            }
            product.deleted = true;
            await db.SaveChangesAsync();

            return(Ok(product));
        }
Пример #8
0
 public async Task CreateAsync(MerchantProduct newMerchantProduct)
 {
     await _mongoDbContext.MerchantProducts.InsertOneAsync(newMerchantProduct);
 }
Пример #9
0
        public async Task UpdateAsync(string sku, Guid merchantCode, Guid merchantAddressCode, MerchantProduct merchantProduct)
        {
            var filter = Builders <MerchantProduct> .Filter.Eq(x => x.Sku, sku) &
                         Builders <MerchantProduct> .Filter.Eq(x => x.MerchantCode, merchantCode) &
                         Builders <MerchantProduct> .Filter.Eq(x => x.MerchantAddressCode, merchantAddressCode);

            var update = Builders <MerchantProduct> .Update.Set(x => x.IsActive, merchantProduct.IsActive)
                         .Set(x => x.IsInfiniteStock, merchantProduct.IsInfiniteStock)
                         .Set(x => x.Stock, merchantProduct.Stock)
                         .Set(x => x.Price, merchantProduct.Price)
                         .Set(x => x.PriceWithVat, merchantProduct.PriceWithVat)
                         .Set(x => x.Vat, merchantProduct.Vat)
                         .Set(x => x.Name, merchantProduct.Name);

            await _mongoDbContext.MerchantProducts.FindOneAndUpdateAsync(filter, update);
        }
 public MerchantProductCreatedEvent(MerchantProduct merchantProduct)
 {
     this.merchantProduct = merchantProduct;
 }