Example #1
0
        public ActionResult InsertAsync(UserAllocation entity)
        {
            entity.CreatorId   = mLogin.Id.ToString();
            entity.CreatedTime = DateTime.Now;

            //所有AJAX的结果,返回统一数据格式
            var result = new AjaxResult();

            try
            {
                if (UserAccountContract.GetByKey(entity.UaId).UserStare != 2)
                {
                    result.Type    = AjaxResultType.Error;
                    result.Content = "当前账户没有通过或已经被禁用";
                }
                else
                {
                    //判断是否已经存在码被分配
                    var isok = UserAllocationContract.Entities.Where(d => d.IsDeleted == false && ((d.StartNumber <= entity.StartNumber && d.EndNumber >= entity.StartNumber) ||
                                                                                                   (d.StartNumber <= entity.EndNumber && d.EndNumber >= entity.EndNumber) || (d.StartNumber >= entity.StartNumber && d.StartNumber <= entity.EndNumber) ||
                                                                                                   (d.EndNumber >= entity.StartNumber && d.EndNumber <= entity.EndNumber))).Count() > 0;
                    if (isok)
                    {
                        result.Type    = AjaxResultType.Error;
                        result.Content = "您输入的码已经被分配";
                    }
                    else
                    {
                        var count = UserAllocationContract.Insert(entity);
                        if (count > 0)
                        {
                            result.Type    = AjaxResultType.Success;
                            result.Content = "录入成功";
                        }
                        else
                        {
                            result.Type    = AjaxResultType.Error;
                            result.Content = "录入失败";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Type    = AjaxResultType.Error;
                result.Content = "异常操作";
            }
            return(JsonEx(result));
        }
Example #2
0
        /// <summary>
        /// 加载编辑页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            if (id == 0)
            {
                throw new Exception("参数错误");
            }

            var entity = UserAccountContract.GetByKey(id);

            //    //后台容错,有异常数据直接抛出。框架会自动跳转到错误页面。
            if (entity == null)
            {
                throw new Exception("未找到该实体");
            }


            ViewData["entity"] = entity;
            return(View());
        }