Пример #1
0
        public RES LoadOrderList()
        {
            var db        = ModelEF.GetInst();
            var orderList = db.YunOrders.ToList();

            return(RES.New.SetAsOK(orderList));
        }
Пример #2
0
        public List <Dictionary <string, object> > ExecuteSQL(string sql, object param)
        {
            var paramaArray = new List <SqlParameter>();

            if (param is string)
            {
                var paramaDict = JSON.ToObject <Dictionary <string, object> >(param.ToString());
                foreach (var item in paramaDict)
                {
                    paramaArray.Add(new SqlParameter(item.Key, item.Value));
                }
            }
            //else if (param is object[])
            //{
            //    paramaArray = param as object[];
            //}
            else if (null == param)
            {
                paramaArray = null;
            }


            var db  = ModelEF.GetInst().Database;
            var res = db.SqlQuery <Dictionary <string, object> >(sql, paramaArray.ToArray()).ToList();

            db.Connection.Close();
            return(res);
        }
        /// <summary>
        /// 保存一个实体
        /// </summary>
        /// <returns></returns>
        public RES Save()
        {
            try
            {
                var db = ModelEF.GetInst();

                if (this.ID == Guid.Empty)
                {
                    this.ID = Guid.NewGuid();
                    db.YunRelations.Add(this);
                }
                else
                {
                    var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == this.ID);
                    if (null != currentEntity)
                    {
                        currentEntity.Name = this.Name;
                    }
                }

                db.SaveChangesAsync();
                return(RES.OK());
            }
            catch (Exception ex)
            {
                return(RES.FAIL());
            }
        }
        ///
        ///保存一个商品
        public RES Save(YunCommodity newData)
        {
            var newVal = JSON.ToObject <YunForm>(JSON.ToJson(newData));
            var db     = ModelEF.GetInst();
            var oldVal = db.YunForms.FirstOrDefault(p => p.ID == newVal.ID);

            if (null == oldVal)
            {
                newVal.InitialDateTime();
                var inst = db.YunForms.Add(newVal);
                db.SaveChanges();
                return(RES.New.SetAsOK(newVal));
            }
            else
            {
                var properties = newVal.GetType().GetProperties().ToList();
                properties.ForEach(p =>
                {
                    var targetProperty = oldVal.GetType().GetProperty(p.Name);
                    if (null != targetProperty && targetProperty.CanWrite)
                    {
                        targetProperty.SetValue(oldVal, p.GetValue(newVal));
                    }
                });
                db.SaveChanges();
                return(RES.New.SetAsOK(oldVal));
            }
        }
 /// <summary>
 /// 移动一个节点
 /// </summary>
 /// <param name="nodeIdStr"></param>
 /// <param name="sourceParentIDStr"></param>
 /// <param name="targetParentNodeIDStr"></param>
 /// <returns></returns>
 public RES MoveNode(string nodeIdStr, string sourceParentIDStr, string targetParentNodeIDStr)
 {
     try
     {
         if (GUID.IsGuid(nodeIdStr) && GUID.IsGuid(sourceParentIDStr) && GUID.IsGuid(targetParentNodeIDStr))
         {
             var currentNodeID      = Guid.Parse(nodeIdStr);
             var sourceParentNodeID = Guid.Parse(sourceParentIDStr);
             var targetParentNodeID = Guid.Parse(targetParentNodeIDStr);
             var db            = ModelEF.GetInst();
             var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == currentNodeID);
             if (null != currentEntity)
             {
                 currentEntity.ParentID = targetParentNodeID;
             }
             db.SaveChangesAsync();
             return(RES.OK());
         }
         return(RES.FAIL());
     }
     catch (Exception ex)
     {
         return(RES.FAIL());
     }
 }
        public RES Load(string id)
        {
            var db    = ModelEF.GetInst();
            var guid  = Guid.Parse(id);
            var query = from item in db.YunForms where item.ID == guid select item;

            return(RES.New.SetAsOK(query.FirstOrDefault()));
        }
        public RES Remove()
        {
            var res     = RES.New;
            var db      = ModelEF.GetInst();
            var data_db = db.YunForms.FirstOrDefault(p => p.ID == this.ID);

            db.YunForms.Remove(data_db);
            db.SaveChanges();
            return(res.SetAsOK());
        }
        public RES LoadList(long formType)
        {
            var res = RES.New;
            var db  = ModelEF.GetInst();

            var query = from item in db.YunForms where formType == item.FormType orderby CreateTime descending select item;

            res.DATA = query.ToList();
            return(res.SetAsOK());
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="rootId"></param>
 /// <returns></returns>
 public RES LoadList(string rootId)
 {
     if (GUID.IsGuid(rootId))
     {
         var rootID = Guid.Parse(rootId);
         var db     = ModelEF.GetInst();
         var res    = db.YunRelations.Where(p => p.RootID == rootID);
         return(RES.New.SetAsOK(res));
     }
     return(RES.New.SetAsFail());
 }
        public RES LoadList_Comment(string sourceIDStr)
        {
            var res      = RES.New;
            var db       = ModelEF.GetInst();
            var formType = (int)ENUM.ServiceType.云评论;
            var sourceID = Guid.Parse(sourceIDStr);
            var query    = from item in db.YunForms where formType == item.FormType && sourceID == item.SourceID select item;

            res.DATA = query.ToList();
            return(res.SetAsOK());
        }
Пример #11
0
        /// <summary>
        /// 加载一个订单
        /// </summary>
        /// <returns></returns>
        public RES LoadOrder(string orderID)
        {
            var res        = RES.New;
            var orderGuid  = ORDER.OrderIDToGuid(orderID);
            var db         = ModelEF.GetInst();
            var order      = db.YunOrders.FirstOrDefault(p => p.ID == orderGuid);
            var qrCodeList = db.YunQRCodes.Where(p => p.OrderID == orderGuid).ToList();

            order.QRCodeList = qrCodeList;
            res.DATA         = order;
            return(res.SetAsOK());
        }
 /// <summary>
 /// 检索一个商品信息 ID,Code
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public RES Get(string keyword)
 {
     if (GUID.IsGuid(keyword))
     {
         var db   = ModelEF.GetInst();
         var guid = Guid.Parse(keyword);
         var val  = db.YunForms.FirstOrDefault(p => p.ID == guid);
         var inst = ModelEF.GetInst().YunForms.FirstOrDefault(p => p.ID == Guid.Parse(keyword));
         return(RES.New.SetAsOK(inst));
     }
     return(RES.New.SetAsFail());
 }
Пример #13
0
 public RES LoadList(string filter)
 {
     try
     {
         var db      = ModelEF.GetInst();
         var titleId = GUID.FromStringToGuid("Title");
         var list    = db.YunFormInsts.Where(p => p.CreateTime <= DateTime.Now && p.PropertyID == titleId).ToList();
         return(RES.OK(list));
     }
     catch (Exception ex)
     {
         return(RES.FAIL());
     }
 }
Пример #14
0
 public RES Save(string json)
 {
     try
     {
         var logItem = JSON.ToObject <ALog>(json);
         var db      = ModelEF.GetInst();
         db.ALogs.Add(logItem);
         db.SaveChangesAsync();
         return(RES.OK());
     }
     catch (Exception e)
     {
         return(RES.FAIL(e.Message));
     }
 }
        ///下架
        public RES OffShelves(string keyword)
        {
            var db = ModelEF.GetInst();

            if (GUID.IsGuid(keyword))
            {
                var guid = Guid.Parse(keyword);
                var val  = db.YunForms.FirstOrDefault(p => p.ID == guid);
                if (null != val)
                {
                    val.ValueI01 = (int)ENUM.CommodityStatus.架;
                }
                db.SaveChanges();
            }

            return(RES.New.SetAsOK());
        }
        ///删除商品
        public RES Remove(string keyword)
        {
            var db = ModelEF.GetInst();

            if (GUID.IsGuid(keyword))
            {
                var guid = Guid.Parse(keyword);
                var val  = db.YunForms.FirstOrDefault(p => p.ID == guid);
                if (null != val)
                {
                    val.Status = (int)ENUM.实体状态.已删除;
                }
                db.SaveChanges();
            }

            return(RES.New.SetAsOK());
        }
Пример #17
0
 public RES LoadDetail(string idStr)
 {
     try
     {
         if (GUID.IsGuid(idStr))
         {
             var id     = Guid.Parse(idStr);
             var db     = ModelEF.GetInst();
             var entity = db.YunFormInsts.FirstOrDefault(p => p.ID == id);
             return(RES.OK(entity));
         }
         return(RES.FAIL());
     }
     catch (Exception ex)
     {
         return(RES.FAIL());
     }
 }
 /// <summary>
 /// 获取当前节点信息
 /// </summary>
 /// <param name="nodeId"></param>
 /// <returns></returns>
 public RES GetCurrentNode(string nodeId)
 {
     if (GUID.IsGuid(nodeId))
     {
         try
         {
             var nId           = Guid.Parse(nodeId);
             var db            = ModelEF.GetInst();
             var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == nId);
             return(RES.OK(currentEntity));
         }
         catch (Exception ex)
         {
             return(RES.FAIL());
         }
     }
     return(RES.FAIL());
 }
 /// <summary>
 /// 获取子节点集合
 /// </summary>
 /// <param name="nodeId"></param>
 /// <returns></returns>
 public RES GetChildNodes(string nodeId)
 {
     if (GUID.IsGuid(nodeId))
     {
         try
         {
             var nId        = Guid.Parse(nodeId);
             var db         = ModelEF.GetInst();
             var childNodes = db.YunRelations.Where(p => p.ParentID == nId);
             return(RES.OK(childNodes));
         }
         catch (Exception ex)
         {
             return(RES.FAIL());
         }
     }
     return(RES.FAIL());
 }
Пример #20
0
        /// <summary>
        /// 保存一个ToDo
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public RES SaveToDo(string idStr, string title, string content)
        {
            try
            {
                var         db          = ModelEF.GetInst();
                var         titleId     = GUID.FromStringToGuid("Title");
                var         contentId   = GUID.FromStringToGuid("Content");
                YunFormInst titleInst   = null;
                YunFormInst contentInst = null;
                if (GUID.IsGuid(idStr))
                {
                    var id      = Guid.Parse(idStr);
                    var oldInst = db.YunFormInsts.Where(p => p.ID == id);
                    if (null != oldInst)
                    {
                        titleInst = oldInst.FirstOrDefault(p => p.PropertyID == titleId);
                        titleInst.PropertyValueString = title;
                        titleInst.UpdateTime          = DateTime.Now;

                        contentInst = oldInst.FirstOrDefault(p => p.PropertyID == contentId);
                        contentInst.PropertyValueString = title;
                        contentInst.UpdateTime          = DateTime.Now;
                    }
                }
                else
                {
                    titleInst = new YunFormInst {
                        ID = Guid.NewGuid(), CreateTime = DateTime.Now, PropertyID = titleId, PropertyValueString = title
                    };

                    contentInst = new YunFormInst {
                        ID = Guid.NewGuid(), CreateTime = DateTime.Now, PropertyID = contentId, PropertyValueString = content
                    };
                    db.YunFormInsts.Add(titleInst);
                    db.YunFormInsts.Add(contentInst);
                }
                var rInt = db.SaveChanges();
                return(RES.OK(rInt));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex.Message));
            }
        }
Пример #21
0
        /// <summary>
        /// 验证一个订单
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public RES QRCodeCheckIn(string json)
        {
            var param       = JSON.ToObject <Dictionary <string, object> >(json);
            var orderId     = Guid.Parse(param["OrderId"].ToString());
            var refundCount = 0;            //
            var qrCode      = string.Empty; //
            var db          = ModelEF.GetInst();
            var order       = db.YunOrders.FirstOrDefault(p => p.ID == orderId);

            if (param.ContainsKey("QRCode") && null != param["QRCode"])
            {
                qrCode           = param["QRCode"].ToString();
                order.QRCodeList = db.YunQRCodes.Where(p => p.OrderID == orderId && p.QRCode == qrCode).Take(1).ToList();;
            }
            else if (param.ContainsKey("Count") && null != param["Count"])
            {
                refundCount      = int.Parse(param["Count"].ToString());
                order.QRCodeList = db.YunQRCodes.Where(p => p.OrderID == orderId).Take(refundCount).ToList();
            }


            order.QRCodeList.ForEach(p =>
            {
                p.Status = (int)ENUM.订单及消费项状态.无可用项目;
            });

            if (0 < order.QRCodeList.Count(p => p.Status == (int)ENUM.订单及消费项状态.未使用))
            {
                ///若还有可使用的
                order.Status = (int)ENUM.订单及消费项状态.部分使用;
            }
            else if (0 < order.QRCodeList.Count(p => p.Status == (int)ENUM.订单及消费项状态.已退款) && order.QRCodeList.Count(p => p.Status == (int)ENUM.订单及消费项状态.已退款) == order.QRCodeList.Count())
            {
                order.Status = (int)ENUM.订单及消费项状态.全部已退款;
            }
            else if (0 == order.QRCodeList.Count(p => p.Status == (int)ENUM.订单及消费项状态.未使用))
            {
                order.Status = (int)ENUM.订单及消费项状态.无可用项目;
            }


            db.SaveChanges();
            return(RES.New.SetAsOK(order));
        }
Пример #22
0
        /// <summary>
        /// 支付一个订单
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public RES PayOrder(string json)
        {
            var param      = JSON.ToObject <Dictionary <string, object> >(json);
            var orderId    = Guid.Parse(param["OrderId"].ToString());
            var db         = ModelEF.GetInst();
            var order      = db.YunOrders.FirstOrDefault(p => p.ID == orderId);
            var qrCodeList = db.YunQRCodes.Where(p => p.OrderID == orderId).ToList();

            order.QRCodeList = qrCodeList;

            order.Status = (int)ENUM.订单及消费项状态.未使用;
            qrCodeList.ForEach(p => {
                p.Status = (int)ENUM.订单及消费项状态.未使用;
            });

            db.SaveChanges();

            return(RES.New.SetAsOK(order));
        }
Пример #23
0
        /// <summary>
        /// 保存一个文档
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <returns></returns>

        public RES SaveArticle(string title, string content, int status = 0)
        {
            try
            {
                var inst = new YunArticle();
                inst.ID      = Guid.NewGuid();
                inst.Status  = status;
                inst.Title   = title;
                inst.Content = content;
                var db = ModelEF.GetInst();
                db.YunArticles.Add(inst);
                db.SaveChangesAsync();
                return(RES.OK(inst));
            }
            catch (Exception ex)
            {
                return(RES.FAIL());
            }
        }
 /// <summary>
 /// 获取整棵树
 /// </summary>
 /// <returns></returns>
 public RES GetWholeTree(string rootID)
 {
     if (GUID.IsGuid(rootID))
     {
         try
         {
             var nId      = Guid.Parse(rootID);
             var db       = ModelEF.GetInst();
             var nodes    = db.YunRelations.Where(p => p.RootID == nId).ToList();
             var rootNode = db.YunRelations.FirstOrDefault(p => p.ID == nId);
             nodes.Add(rootNode);
             return(RES.OK(nodes));
         }
         catch (Exception ex)
         {
             return(RES.FAIL());
         }
     }
     return(RES.FAIL());
 }
        public virtual RES SaveToSQLServer()
        {
            if (Guid.Empty == this.ID)
            {
                this.ID = Guid.NewGuid();
            }
            HttpPostedFile file = HttpContext.Current.Request.Files[0];

            var bytes = new byte[(int)file.InputStream.Length];

            file.InputStream.Read(bytes, 0, bytes.Length);

            this.BinData = bytes;
            var res = RES.New;
            var db  = ModelEF.GetInst();

            db.YunForms.Add(this);
            db.SaveChanges();
            return(res);
        }
        /// <summary>
        /// 同步保存一个对象
        /// </summary>
        /// <returns></returns>
        public virtual RES Save()
        {
            var res = RES.New;

            if (Guid.Empty == this.ID)
            {
                this.ID         = Guid.NewGuid();
                this.CreateTime = DateTime.Now;
                if (!this.Status.HasValue)
                {
                    this.Status = (int)ENUM.实体状态.正常;
                }
            }
            ;

            var db = ModelEF.GetInst();

            db.YunForms.Add(this);
            db.SaveChanges();
            return(res);
        }
 /// <summary>
 /// 移除一个子节点
 /// </summary>
 /// <param name="nodeId"></param>
 /// <returns></returns>
 public RES RemoveNode(string nodeId)
 {
     if (GUID.IsGuid(nodeId))
     {
         try
         {
             var nId           = Guid.Parse(nodeId);
             var db            = ModelEF.GetInst();
             var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == nId);
             if (null != currentEntity)
             {
                 currentEntity.Status = (int)ENUM.实体状态.已删除;
             }
             db.SaveChangesAsync();
             return(RES.OK());
         }
         catch (Exception ex)
         {
             return(RES.FAIL());
         }
     }
     return(RES.FAIL());
 }
 /// <summary>
 /// 修改一个子节点的信息
 /// </summary>
 /// <param name="nodeId"></param>
 /// <returns></returns>
 public RES RenameNode(string nodeId, string newName)
 {
     if (GUID.IsGuid(nodeId) && !string.IsNullOrWhiteSpace(newName))
     {
         try
         {
             var nId           = Guid.Parse(nodeId);
             var db            = ModelEF.GetInst();
             var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == nId);
             if (null != currentEntity)
             {
                 currentEntity.Name = newName;
             }
             db.SaveChangesAsync();
             return(RES.OK());
         }
         catch (Exception ex)
         {
             return(RES.FAIL());
         }
     }
     return(RES.FAIL());
 }
Пример #29
0
 /// <summary>
 /// 从url中保存一个原始文章
 /// </summary>
 /// <param name="url"></param>
 /// <param name="headers"></param>
 /// <returns></returns>
 public RES SaveArticleFromUrl(string url, string headers)
 {
     try
     {
         var content = HTTP.Get(url, string.IsNullOrWhiteSpace(headers) ? null: JSON.ToObject <Dictionary <string, string> >(headers));
         var inst    = new YunArticle();
         inst.ID         = Guid.NewGuid();
         inst.Status     = (int)ENUM.实体状态.可用;
         inst.Title      = null;
         inst.Url        = url;
         inst.Content    = content;
         inst.CreateTime = DateTime.Now;
         inst.UpdateTime = DateTime.Now;
         var db = ModelEF.GetInst();
         db.YunArticles.Add(inst);
         db.SaveChangesAsync();
         return(RES.OK(inst));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex.Message));
     }
 }
Пример #30
0
        /// <summary>
        /// 创建一个未支付订单
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public RES CreatePrepayOrder(string goodsIDStr, long count, string sourceIDStr, string consumerIDStr)
        {
            var res = RES.New;

            if (!string.IsNullOrWhiteSpace(goodsIDStr) && 0 < count && !string.IsNullOrWhiteSpace(goodsIDStr) && !string.IsNullOrWhiteSpace(goodsIDStr))
            {
                var db = ModelEF.GetInst();
                ///若数据符合要求
                var goodsID    = new Guid(goodsIDStr);
                var sourceID   = new Guid(sourceIDStr);
                var consumerID = new Guid(consumerIDStr);
                var yunOrder   = new YunOrder();
                yunOrder.GoodsID    = goodsID;
                yunOrder.SourceID   = sourceID;
                yunOrder.ConsumerID = consumerID;
                yunOrder.Count      = (int)count;
                yunOrder.ID         = Guid.NewGuid();
                yunOrder.Status     = (int)ENUM.订单及消费项状态.未支付;
                //yunOrder.OrderID =GUID. MD5.ToMD5( ORDER.NewOrderID);

                for (int k = 0; k < count; k++)
                {
                    var item = new YunQRCode();
                    item.ID      = Guid.NewGuid();
                    item.OrderID = yunOrder.ID;
                    item.QRCode  = item.OrderID.ToString() + k;
                    //item.Status = (int)ENUM.EntityStatus.正常;
                    item.Status = (int)ENUM.订单及消费项状态.未支付;
                    db.YunQRCodes.Add(item);
                }

                db.YunOrders.Add(yunOrder);
                db.SaveChanges();
            }
            return(res.SetAsOK());
        }