Exemplo n.º 1
0
        /// <summary>
        /// 获取联系人前8条
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public IActionResult GetListByKey(string key)
        {
            IEnumerable <ClientInfo> list;

            if (string.IsNullOrEmpty(key))
            {
                list = _clientInfoRepository.FindBy(e => e.UserId == CurrentUser.Id && e.IsDel == 0).Take(8).ToList();
            }
            else
            {
                list = _clientInfoRepository.FindBy(e => e.UserId == CurrentUser.Id && e.IsDel == 0 && e.ClientName.Contains(key)).Take(8).ToList();
            }

            List <dynamic> dyList = new List <dynamic>();

            list.ToList().ForEach(e =>
            {
                dyList.Add(new { value = e.ClientName, id = e.Id });
            });

            return(JsonOk(dyList));
        }
Exemplo n.º 2
0
        public IActionResult AddOrder([FromBody] OrderInfoView orderInfoView)
        {
            var userId = CurrentUser.Id;

            if (string.IsNullOrEmpty(orderInfoView.ClientName))
            {
                return(JsonError("客户信息未填写"));
            }
            orderInfoView.ClientName = orderInfoView.ClientName.Trim();
            if (orderInfoView.ClientId == null)
            {
                var clientModel = _clientInfoRepository.FindBy(e => e.UserId == userId && e.ClientName == orderInfoView.ClientName && e.IsDel == 0);

                if (clientModel.Any())
                {
                    return(JsonError("该客户信息已存在,请直接选择"));
                }
                else
                {
                    ClientInfo clientInfo = new ClientInfo()
                    {
                        ClientName = orderInfoView.ClientName,
                        UserId     = userId,
                        IsDel      = 0,
                        CreateTime = DateTime.Now,
                        UpdateTime = DateTime.Now
                    };

                    var clientId = _clientInfoRepository.Add(clientInfo);
                    orderInfoView.ClientId = clientId;
                }
            }

            try
            {
                orderInfoView.UserId = userId;
                _orderInfoRepository.AddOrder(orderInfoView);
                return(JsonOk(""));
            }
            catch (Exception e)
            {
                return(JsonError(e.Message));
            }
        }