public async Task <IActionResult> SaveOrder(int mallProductSnapshotId, int mallCustomerId, DateTime date, int ordered, int gift, decimal price)
        {
            var dateStr   = GetDateString(date);
            var mallOrder = await _mallOrderRepository.GetSingleAsync(x =>
                                                                      x.MallProductSnapshotId == mallProductSnapshotId && x.MallCustomerId == mallCustomerId && x.Date == dateStr);

            if (mallOrder == null)
            {
                mallOrder = new MallOrder
                {
                    MallProductSnapshotId = mallProductSnapshotId,
                    MallCustomerId        = mallCustomerId,
                    Date    = dateStr,
                    Ordered = ordered,
                    Gift    = gift,
                    Price   = price
                };
                mallOrder.SetCreation(UserName);
                _mallOrderRepository.Add(mallOrder);
            }
            else
            {
                mallOrder.Ordered = ordered;
                mallOrder.Gift    = gift;
                mallOrder.Price   = price;
                mallOrder.SetModification(UserName);
                _mallOrderRepository.Update(mallOrder);
            }
            if (!await UnitOfWork.SaveAsync())
            {
                return(StatusCode(500, "保存时出错"));
            }

            return(NoContent());
        }
Example #2
0
 /// <summary>
 /// 插入订单操作
 /// </summary>
 /// <param name="orderInfo"></param>
 /// <returns></returns>
 public JObject SubmitDlInfo(JObject orderInfo)
 {
     using (var db = new RepositoryBase().BeginTrans())
     {
         int         flag     = 0;
         var         ret      = new JObject();
         GameAccount _account = JsonConvert.DeserializeObject <GameAccount>(orderInfo.ToString());
         MallOrder   order    = JsonConvert.DeserializeObject <MallOrder>(orderInfo.ToString());
         order.OrderNo = Common.CreatOrderNo(order.GoodNo);
         if (!string.IsNullOrEmpty(_account.Account) && !string.IsNullOrEmpty(order.OrderNo))
         {
             db.Insert(_account);
             db.Insert(order);
         }
         flag = db.Commit();
         if (flag == 2)//两笔都插入成功
         {
             ret.Add(ResultInfo.Result, true);
             ret.Add(ResultInfo.Content, "提交成功!");
         }
         else
         {
             ret.Add(ResultInfo.Result, false);
             ret.Add(ResultInfo.Content, "保存失败请重新尝试!");
         }
         return(ret);
     }
 }
        public JObject CreatOrder(JObject json)
        {
            MallOrder goodInfo = JsonConvert.DeserializeObject <MallOrder>(json.First.Path);

            return(service.CreatOrder(goodInfo));
        }