public ActionResult Detail(int id)
        {
            using (var db = new YGSDbContext())
            {
                var history = db.History.Where(n => n.ID == id).FirstOrDefault();

                if (history == null)
                {
                    return(ResponseUtil.Error(400, "履历不存在"));
                }
                else
                {
                    return(new JsonNetResult(new
                    {
                        code = 200,
                        data = new
                        {
                            id = history.ID,
                            signNo = history.SignNo,
                            signTime = history.SignTime,
                            signNation = history.SignNation,
                            isOut = history.IsOut
                        }
                    }));
                }
            }
        }
 public ActionResult Detail(int id)
 {
     /*
      * 获取用户
      */
     using (var db = new YGSDbContext())
     {
         var user = db.User.Where(n => n.ID == id).FirstOrDefault();
         if (user == null)
         {
             return(ResponseUtil.Error(400, "用户不存在"));
         }
         else
         {
             return(new JsonNetResult(new
             {
                 code = 200,
                 data = new
                 {
                     id = user.ID,
                     name = user.Name,
                     sex = user.Sex,
                     location = user.Location,
                     birthDay = user.BirthDay == null ? null : user.BirthDay.Value.ToString("yyyy/MM/dd"),
                     credNo = user.CredNo,
                     unit = user.Unit,
                     depart = user.Depart,
                     level = user.Level,
                     duty = user.Duty
                 }
             }));
         }
     }
 }
Exemple #3
0
        public ActionResult Download(int id)
        {
            using (var db = new YGSDbContext())
            {
                var attach = db.Attachment.Where(a => a.ID == id).FirstOrDefault();
                if (attach == null)
                {
                    return(ResponseUtil.Error(404, "图片不存在"));
                }
                else
                {
                    var    filename       = attach.Path;
                    var    fullUploadPath = System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
                    string filepath       = Path.Combine(fullUploadPath, filename);
                    byte[] filedata       = System.IO.File.ReadAllBytes(filepath);
                    string contentType    = MimeMapping.GetMimeMapping(filepath);

                    //var cd = new System.Net.Mime.ContentDisposition
                    //{
                    //    FileName = attach.Name,
                    //    Inline = true,
                    //};

                    //Response.AppendHeader("Content-Disposition", cd.ToString());

                    //return File(filedata, contentType);
                    return(File(filedata, contentType, attach.Name));
                }
            }
        }
Exemple #4
0
        public ActionResult Delete(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 申请ID
            int aid = 0;

            /*
             * 参数获取
             */
            // 申请id
            var id = collection["id"];

            /*
             * 参数校验
             */
            // 申请ID
            if (string.IsNullOrEmpty(id))
            {
                return(ResponseUtil.Error(400, "申请ID不能为空"));
            }
            else
            {
                if (!int.TryParse(id, out aid))
                {
                    return(ResponseUtil.Error(400, "申请ID不正确"));
                }
            }

            /*
             * 删除申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = db.Apply.Where(n => n.ID == aid).FirstOrDefault();
                if (apply == null)
                {
                    return(ResponseUtil.Error(400, "申请不存在"));
                }
                else
                {
                    // 查询所有对应的履历
                    // 获得所有外出人员id
                    //var historyIdList = apply.OutUsers.Split(',').Select(int.Parse).ToList();
                    //var historyList = db.History.Where(n => historyIdList.Contains(n.ID)).ToList();
                    //db.History.RemoveRange(historyList);
                    //db.Apply.Remove(apply);
                    apply.IsDelete = true;
                    db.SaveChanges();
                    return(ResponseUtil.OK(200, "删除成功"));
                }
            }
        }
        public ActionResult Delete(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 用户ID
            int id = 0;

            /*
             * 参数获取
             */
            // 用户ID
            var userId = collection["id"];

            /*
             * 参数校验
             */
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out id))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }

            /*
             * 用户查询
             */
            using (var db = new YGSDbContext())
            {
                var user = db.User.Where(n => n.ID == id).FirstOrDefault();
                if (user == null)
                {
                    return(ResponseUtil.Error(400, "用户不存在"));
                }
                else
                {
                    // 检查该用户是否有护照信息,也要一并删除
                    var credList = db.Cred.Where(n => n.UserID == id).ToList();
                    db.Cred.RemoveRange(credList);
                    db.User.Remove(user);
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "用户删除成功"));
                }
            }
        }
Exemple #6
0
        public ActionResult Upload()
        {
            try
            {
                // 个人上传文件夹检查
                var folder     = System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
                var folderPath = folder;
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                // 提取上传的文件
                HttpPostedFileBase file = Request.Files[0];

                // 原文件名 Test.txt
                var fileName = Path.GetFileName(file.FileName);
                // 最终文件名 yyyyMMddHHmmss+4random.txt
                var finalFileName = DiskUtil.GetFinalFileName(fileName);
                // 最终存储路径
                var path = Path.Combine(folderPath, finalFileName);

                // 保存文件
                file.SaveAs(path);

                // 判断上传的是反馈文件还是客户签字单
                var att = new YGS_Att();
                att.Name = fileName;
                att.Path = Path.Combine(finalFileName).Replace("\\", "/");

                using (var db = new YGSDbContext())
                {
                    db.Attachment.Add(att);
                    db.SaveChanges();
                }

                return(new JsonNetResult(new
                {
                    status = 200,
                    data = new
                    {
                        id = att.ID,
                        name = att.Name,
                        path = Url.Action("Download", "Common", new { id = att.ID })
                    }
                }));
            }
            catch
            {
                return(ResponseUtil.Error(400, "上传出错"));
            }
        }
Exemple #7
0
        public ActionResult Delete(int id)
        {
            /*
             * 证件查询
             */
            using (var db = new YGSDbContext())
            {
                var cred = db.Cred.Where(n => n.ID == id).FirstOrDefault();
                if (cred == null)
                {
                    return(ResponseUtil.Error(400, "证件不存在"));
                }
                else
                {
                    db.Cred.Remove(cred);
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "删除成功"));
                }
            }
        }
        public ActionResult Delete(int id)
        {
            /*
             * 查询履历
             */
            using (var db = new YGSDbContext())
            {
                var history = db.History.Where(n => n.ID == id).FirstOrDefault();

                if (history == null)
                {
                    return(ResponseUtil.Error(400, "履历不存在"));
                }
                else
                {
                    db.History.Remove(history);
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "删除成功"));
                }
            }
        }
Exemple #9
0
        public ActionResult CompleteUser(FormCollection collection)
        {
            /*
             * 参数获取
             */
            // 姓名
            var Name = collection["name"];

            /*
             * 参数校验
             */
            // 姓名
            if (string.IsNullOrEmpty(Name))
            {
                return(ResponseUtil.Error(400, "姓名不能为空"));
            }

            /*
             * 查询符合条件的用户
             */
            using (var db = new YGSDbContext())
            {
                var users = db.User.Where(n => n.Name.Contains(Name)).Select(n => new {
                    id      = n.ID,
                    name    = n.Name,
                    cred_no = n.CredNo
                }).ToList();
                return(new JsonNetResult(new
                {
                    code = 200,
                    data = new
                    {
                        users = users
                    }
                }));
            }
        }
        public ActionResult Delete(int id)
        {
            using (var db = new YGSDbContext())
            {
                var apply = db.Apply.Where(n => n.ID == id).FirstOrDefault();
                if (apply == null)
                {
                    return(ResponseUtil.Error(400, "申请不存在"));
                }
                else
                {
                    // 查询所有对应的履历
                    // 获得所有外出人员id
                    //var historyIdList = apply.OutUsers.Split(',').Select(int.Parse).ToList();
                    //var historyList = db.History.Where(n => historyIdList.Contains(n.ID)).ToList();
                    //db.History.RemoveRange(historyList);
                    //db.Apply.Remove(apply);
                    apply.IsDelete = true;
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "删除成功"));
                }
            }
        }
Exemple #11
0
        public ActionResult DoUpdate(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 证件ID
            int tradeId = 0;
            // 发照日期
            DateTime credDate = new DateTime();
            // 有效期
            DateTime validDate = new DateTime();

            /*
             * 参数获取
             */
            // 证件ID
            var tradeIdString = collection["tradeId"];
            // 证件号
            var tradeCode = collection["tradeCode"];
            // 证件类型
            var credType = collection["credType"];
            // 发照机关
            var credUnit = collection["credUnit"];
            // 发照日期
            var credDateString = collection["credDate"];
            // 有效期
            var validDateString = collection["validDate"];
            // 有效状态
            var validStatus = collection["validStatus"];

            /*
             * 参数校验
             */
            // 证件ID
            if (string.IsNullOrEmpty(tradeIdString))
            {
                return(ResponseUtil.Error(400, "证件ID不能为空"));
            }
            else
            {
                if (!int.TryParse(tradeIdString, out tradeId))
                {
                    return(ResponseUtil.Error(400, "证件ID不正确"));
                }
            }
            // 证件号
            if (string.IsNullOrEmpty(tradeCode))
            {
                return(ResponseUtil.Error(400, "证件号不能为空"));
            }
            // 证件类型
            //if (string.IsNullOrEmpty(credType))
            //{
            //    return ResponseUtil.Error(400, "证件类型不能为空");
            //}
            // 发照机关
            //if (string.IsNullOrEmpty(credUnit))
            //{
            //    return ResponseUtil.Error(400, "发照机关不能为空");
            //}
            // 发照日期
            if (!string.IsNullOrEmpty(credDateString))
            {
                if (!DateTime.TryParse(credDateString, out credDate))
                {
                    return(ResponseUtil.Error(400, "发照日期格式不正确"));
                }
            }
            // 有效期
            if (!string.IsNullOrEmpty(validDateString))
            {
                if (!DateTime.TryParse(validDateString, out validDate))
                {
                    return(ResponseUtil.Error(400, "有效期格式不正确"));
                }
            }
            // 有效状态
            //if (string.IsNullOrEmpty(validStatus))
            //{
            //    return ResponseUtil.Error(400, "有效状态不能为空");
            //}

            /*
             * 证件查询
             */
            using (var db = new YGSDbContext())
            {
                var cred = db.Cred.Where(n => n.ID == tradeId).FirstOrDefault();
                if (cred == null)
                {
                    return(ResponseUtil.Error(400, "证件不存在"));
                }
                else
                {
                    var existsCred = db.Cred.Where(n => n.TradeCode == tradeCode).FirstOrDefault();
                    if (existsCred != null && existsCred.ID != cred.ID)
                    {
                        return(ResponseUtil.Error(400, "相同证件号已存在"));
                    }
                    else
                    {
                        cred.TradeCode = tradeCode;
                        cred.CredType  = credType;
                        cred.CredUnit  = credUnit;
                        if (string.IsNullOrEmpty(credDateString))
                        {
                            cred.CredDate = null;
                        }
                        else
                        {
                            cred.CredDate = credDate;
                        }
                        if (string.IsNullOrEmpty(validDateString))
                        {
                            cred.ValidDate = null;
                        }
                        else
                        {
                            cred.ValidDate = validDate;
                        }
                        cred.ValidStatus = validStatus;
                        db.SaveChanges();
                        return(ResponseUtil.OK(200, "更新成功"));
                    }
                }
            }
        }
Exemple #12
0
        public ActionResult DoAdd(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 用户ID
            int uid = 0;
            // 发照日期
            DateTime credDate = new DateTime();
            // 有效期
            DateTime validDate = new DateTime();

            /*
             * 参数获取
             */
            // 用户ID
            var userId = collection["userId"];
            // 证件号
            var tradeCode = collection["tradeCode"];
            // 证件类型
            var credType = collection["credType"];
            // 发照机关
            var credUnit = collection["credUnit"];
            // 发照日期
            var credDateString = collection["credDate"];
            // 有效期
            var validDateString = collection["validDate"];
            // 有效状态
            var validStatus = collection["validStatus"];

            /*
             * 参数校验
             */
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out uid))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }
            // 证件号
            if (string.IsNullOrEmpty(tradeCode))
            {
                return(ResponseUtil.Error(400, "证件号不能为空"));
            }
            // 证件类型
            //if (string.IsNullOrEmpty(credType))
            //{
            //    return ResponseUtil.Error(400, "证件类型不能为空");
            //}
            // 发照机关
            //if (string.IsNullOrEmpty(credUnit))
            //{
            //    return ResponseUtil.Error(400, "发照机关不能为空");
            //}
            // 发照日期
            if (!string.IsNullOrEmpty(credDateString))
            {
                if (!DateTime.TryParse(credDateString, out credDate))
                {
                    return(ResponseUtil.Error(400, "发照日期格式不正确"));
                }
            }
            // 有效期
            if (!string.IsNullOrEmpty(validDateString))
            {
                if (!DateTime.TryParse(validDateString, out validDate))
                {
                    return(ResponseUtil.Error(400, "有效期格式不正确"));
                }
            }
            // 有效状态
            //if (string.IsNullOrEmpty(validStatus))
            //{
            //    return ResponseUtil.Error(400, "有效状态不能为空");
            //}

            /*
             * 用户查询
             */
            using (var db = new YGSDbContext())
            {
                var existsCred = db.Cred.Where(n => n.TradeCode == tradeCode).FirstOrDefault();
                if (existsCred != null)
                {
                    return(ResponseUtil.Error(400, "相同证件号已存在"));
                }
                else
                {
                    var user = db.User.Where(n => n.ID == uid).FirstOrDefault();
                    if (user == null)
                    {
                        return(ResponseUtil.Error(400, "用户不存在"));
                    }
                    else
                    {
                        var cred = new YGS_Cred();
                        cred.UserID    = uid;
                        cred.Name      = user.Name;
                        cred.Sex       = user.Sex;
                        cred.TradeCode = tradeCode;
                        cred.CredType  = credType;
                        cred.CredUnit  = credUnit;
                        if (string.IsNullOrEmpty(credDateString))
                        {
                            cred.CredDate = null;
                        }
                        else
                        {
                            cred.CredDate = credDate;
                        }
                        if (string.IsNullOrEmpty(validDateString))
                        {
                            cred.ValidDate = null;
                        }
                        else
                        {
                            cred.ValidDate = validDate;
                        }
                        cred.ValidStatus = validStatus;
                        cred.CreateTime  = DateTime.Now;
                        cred.UpdateTime  = DateTime.Now;

                        db.Cred.Add(cred);
                        db.SaveChanges();

                        return(ResponseUtil.OK(200, "添加成功"));
                    }
                }
            }
        }
Exemple #13
0
        public ActionResult Update(int id)
        {
            /*
             * 变量定义
             */

            /*
             * 参数
             */
            // 用户获取
            using (var db = new YGSDbContext())
            {
                var cred = db.Cred.Where(n => n.ID == id).FirstOrDefault();
                if (cred == null)
                {
                    return(ResponseUtil.Error(400, "证件不存在"));
                }
                else
                {
                    var user = db.User.Where(n => n.ID == cred.UserID).FirstOrDefault();
                    if (user == null)
                    {
                        return(ResponseUtil.Error(400, "用户不存在"));
                    }
                    else
                    {
                        return(new JsonNetResult(new
                        {
                            code = 200,
                            data = new
                            {
                                credTypes = new object[]
                                {
                                    new {
                                        id = 1,
                                        type = WHConstants.Cred_Type_Passport,
                                        name = "护照"
                                    },
                                    new
                                    {
                                        id = 2,
                                        type = WHConstants.Cred_Type_Permit,
                                        name = "通行证"
                                    }
                                },
                                user = new
                                {
                                    id = user.ID,
                                    credNo = user.CredNo,
                                    name = user.Name,
                                    sex = user.Sex,
                                    location = user.Location,
                                    birthDay = user.BirthDay == null ? null : user.BirthDay.Value.ToString("yyyy/MM/dd"),
                                    unit = user.Unit,
                                    depart = user.Depart,
                                    level = user.Level,
                                    duty = user.Duty
                                },
                                trade = new
                                {
                                    tradeCode = cred.TradeCode,
                                    credType = cred.CredType,
                                    credUnit = cred.CredUnit,
                                    credDate = cred.CredDate == null ? null: cred.CredDate.Value.ToString("yyyy/MM/dd"),
                                    validDate = cred.ValidDate == null ? null: cred.ValidDate.Value.ToString("yyyy/MM/dd"),
                                    validStatus = cred.ValidStatus
                                }
                            }
                        }));
                    }
                }
            }
        }
Exemple #14
0
        public ActionResult Add(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 用户ID
            int id = 0;

            /*
             * 参数获取
             */
            // 用户ID
            var userId = collection["userId"];

            /*
             * 参数校验
             */
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out id))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }

            /*
             * 用户查询
             */
            using (var db = new YGSDbContext())
            {
                var user = db.User.Where(n => n.ID == id).FirstOrDefault();
                if (user == null)
                {
                    return(ResponseUtil.Error(400, "用户不存在"));
                }
                else
                {
                    return(new JsonNetResult(new
                    {
                        code = 200,
                        data = new
                        {
                            credTypes = new object[]
                            {
                                new {
                                    id = 1,
                                    type = WHConstants.Cred_Type_Passport,
                                    name = "护照"
                                },
                                new
                                {
                                    id = 2,
                                    type = WHConstants.Cred_Type_Permit,
                                    name = "通行证"
                                }
                            },
                            user = new
                            {
                                id = user.ID,
                                credNo = user.CredNo,
                                name = user.Name,
                                sex = user.Sex,
                                location = user.Location,
                                birthDay = user.BirthDay == null ? null : user.BirthDay.Value.ToString("yyyy/MM/dd"),
                                unit = user.Unit,
                                depart = user.Depart,
                                level = user.Level,
                                duty = user.Duty
                            }
                        }
                    }));
                }
            }
        }
Exemple #15
0
        public ActionResult List(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 用户ID
            int id = 0;

            /*
             * 参数获取
             */
            // 用户ID
            var userId = collection["userId"];

            /*
             * 参数校验
             */
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out id))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }

            var db   = new YGSDbContext();
            var user = db.User.Where(n => n.ID == id).FirstOrDefault();

            if (user == null)
            {
                return(ResponseUtil.Error(400, "用户不存在"));
            }
            else
            {
                // 证件列表
                var credList = db.Cred.Where(n => n.UserID == id).ToList().Select(n => new
                {
                    id          = n.ID,
                    tradeCode   = n.TradeCode,
                    name        = n.Name,
                    sex         = n.Sex,
                    credUnit    = n.CredUnit,
                    credDate    = n.CredDate == null ? null : n.CredDate.Value.ToString("yyyy/MM/dd"),
                    validDate   = n.ValidDate == null ? null : n.ValidDate.Value.ToString("yyyy/MM/dd"),
                    validStatus = n.ValidStatus
                });
                // 出国记录
                var outRecords = db.Apply.ToList().Where(n => n.OutUsers.Split(',').Select(int.Parse).ToList().Contains(id) && n.ApplyStatus == WHConstants.Apply_Status_Passed).ToList().Select(n => new
                {
                    id         = n.ID,
                    outName    = n.OutName,
                    credType   = n.CredType,
                    signStatus = n.SignStatus,
                    outDate    = n.OutDate == null ? "" : n.OutDate.Value.ToString("yyyy/MM/dd"),
                    //outUsers = db.History.Where(m => m.ApplyId == n.ID).GroupBy(m => m.UserId).Select(m => m.FirstOrDefault()).ToList().Select(m => new
                    //{
                    //    id = m.ID,
                    //    name = db.User.Where(u => u.ID == m.UserId).Select(u => u.Name).FirstOrDefault()
                    //}).ToList(),
                    outUsers = db.User.ToList().Where(m => n.OutUsers.Split(',').Select(int.Parse).ToList().Contains(m.ID)).Select(m => new {
                        id   = m.ID,
                        name = m.Name
                    }),
                    desc    = n.Desc,
                    history = db.History.Where(m => m.ApplyId == n.ID && m.UserId == id).ToList().Select(m => new {
                        id         = m.ID,
                        signNo     = m.SignNo,
                        signTime   = m.SignTime == null ? null : m.SignTime.Value.ToString("yyyy/MM/dd"),
                        signNation = m.SignNation,
                        isOut      = m.IsOut
                    }).ToList(),
                });

                return(new JsonNetResult(new
                {
                    code = 200,
                    data = new
                    {
                        creds = credList,
                        applyRecords = outRecords,
                        userId = userId
                    }
                }));
            }
        }
        public ActionResult List(FormCollection collection)
        {
            using (var db = new YGSDbContext())
            {
                /*
                 * 变量定义
                 */
                // 页数
                int page = WHConstants.Default_Page;
                // 分页大小
                int pageSize = WHConstants.Default_Page_Size;
                // 性别
                int sex = 0;
                // 用户列表
                var userList = db.User.Where(n => !string.IsNullOrEmpty(n.CredNo));

                //var userList = db.User.Where(n => true);

                /*
                 * 参数获取
                 */
                // 姓名
                var name = collection["name"];
                // 性别
                var sexString = collection["sex"];
                // 身份证号
                var credNo = collection["credNo"];
                // 页数
                var pageString = collection["page"];
                // 分页大小
                var pageSizeString = collection["pageSize"];

                /*
                 * 参数校验
                 */
                // 验证分页大小
                if (!string.IsNullOrEmpty(pageString))
                {
                    if (int.TryParse(pageString, out page))
                    {
                        if (page <= 0)
                        {
                            return(ResponseUtil.Error(400, "分页大小错误"));
                        }
                    }
                    else
                    {
                        // 验证出错
                        return(ResponseUtil.Error(400, "分页大小错误"));
                    }
                }
                // 验证页数
                if (!string.IsNullOrEmpty(pageSizeString))
                {
                    if (int.TryParse(pageSizeString, out pageSize))
                    {
                        if (pageSize <= 0)
                        {
                            return(ResponseUtil.Error(400, "页数错误"));
                        }
                    }
                    else
                    {
                        // 验证出错
                        return(ResponseUtil.Error(400, "页数错误"));
                    }
                }
                // 验证姓名
                if (!string.IsNullOrEmpty(name))
                {
                    userList = userList.Where(n => n.Name.Contains(name));
                }
                // 验证性别
                if (!string.IsNullOrEmpty(sexString))
                {
                    if (!int.TryParse(sexString, out sex))
                    {
                        return(ResponseUtil.Error(400, "性别错误"));
                    }
                    else
                    {
                        userList = userList.Where(n => n.Sex == sex);
                    }
                }
                // 验证身份证号
                if (!string.IsNullOrEmpty(credNo))
                {
                    userList = userList.Where(n => n.CredNo.Contains(credNo));
                }

                /*
                 * 分页及数据获取
                 */
                // 记录总数
                // 记录总数
                var totalCount = userList.Count();
                // 记录总页数
                var totalPage = (int)Math.Ceiling((float)totalCount / pageSize);
                // 查询结果数据
                var resultRecords = userList.OrderByDescending(n => n.CreateTime.Value).Skip((page - 1) * pageSize).Take(pageSize).ToList();

                //预约列表格式
                List <object> users = new List <object>();

                foreach (var user in resultRecords)
                {
                    users.Add(new
                    {
                        id     = user.ID,
                        credNo = user.CredNo,
                        name   = user.Name,
                        sex    = user.Sex,
                        unit   = user.Unit,
                        depart = user.Depart,
                        level  = user.Level,
                        duty   = user.Duty
                    });
                }

                return(new JsonNetResult(new
                {
                    code = 200,
                    data = new
                    {
                        users = users,
                        meta = new
                        {
                            current_page = page,
                            total_page = totalPage,
                            current_count = (page - 1) * pageSize + resultRecords.ToList().Count(),
                            total_count = totalCount,
                            per_page = pageSize
                        }
                    }
                }));
            }
        }
        public ActionResult Check(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 申请ID
            int aid = 0;

            /*
             * 参数获取
             */
            // 申请ID
            var id = collection["id"];
            // 审批意见
            var checkOpinion = collection["checkOpinion"];
            // 审批状态
            var checkStatus = collection["checkStatus"];

            /*
             * 参数校验
             */
            // 申请ID
            if (string.IsNullOrEmpty(id))
            {
                return(ResponseUtil.Error(400, "申请ID不能为空"));
            }
            else
            {
                if (!int.TryParse(id, out aid))
                {
                    return(ResponseUtil.Error(400, "申请ID不正确"));
                }
            }
            // 审批意见
            if (string.IsNullOrEmpty(checkOpinion))
            {
                return(ResponseUtil.Error(400, "审批意见不能为空"));
            }
            // 审批状态
            if (string.IsNullOrEmpty(checkStatus))
            {
                return(ResponseUtil.Error(400, "审批状态不能为空"));
            }

            /*
             * 审核逻辑
             */
            using (var db = new YGSDbContext())
            {
                var apply = db.Apply.Where(n => n.ID == aid).FirstOrDefault();
                if (apply == null)
                {
                    return(ResponseUtil.Error(400, "申请不存在"));
                }
                else
                {
                    apply.CheckOpinion = checkOpinion;
                    if (checkStatus == WHConstants.Check_Status_Pass)
                    {
                        // 获得所有外出人员id
                        //var historyIdList = apply.OutUsers.Split(',').Select(int.Parse).ToList();
                        //var outUserIds = db.History.Where(n => historyIdList.Contains(n.ID)).Select(n => n.UserId).ToList();
                        //var illegalUsers = db.User.Where(m => outUserIds.Contains(m.ID) && string.IsNullOrEmpty(m.CredNo)).ToList();

                        //if (illegalUsers.Count > 0)
                        //{
                        //    return ResponseUtil.Error(400, "出国人员缺少身份证号,请先到申请详情中补全");
                        //}
                        //else
                        //{
                        //    apply.ApplyStatus = WHConstants.Apply_Status_Passed;
                        //    NotificationUtil.SendNotification(apply.UserId, "您的出国申请已通过", "/Apps/YGS/Home/");
                        //}
                        apply.ApplyStatus = WHConstants.Apply_Status_Passed;
                        NotificationUtil.SendNotification(apply.UserId, "您的出国申请已通过", "/Apps/YGS/Home/");
                    }
                    else
                    {
                        apply.ApplyStatus = WHConstants.Apply_Status_Rejected;
                        NotificationUtil.SendNotification(apply.UserId, "您的出国申请被拒绝", "/Apps/YGS/Home/");
                    }
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "审批成功"));
                }
            }
        }
 public ActionResult Update(int id)
 {
     /*
      * 查询申请
      */
     using (var db = new YGSDbContext())
     {
         var apply = db.Apply.Where(n => n.ID == id).FirstOrDefault();
         if (apply == null)
         {
             return(ResponseUtil.Error(400, "申请不存在"));
         }
         else
         {
             // 获得所有外出人员id
             var userIdList = apply.OutUsers.Split(',').Select(int.Parse).ToList();
             return(new JsonNetResult(new
             {
                 code = 200,
                 data = new
                 {
                     credTypes = new object[]
                     {
                         new {
                             id = 1,
                             type = WHConstants.Cred_Type_Passport,
                             name = "护照"
                         },
                         new
                         {
                             id = 2,
                             type = WHConstants.Cred_Type_Permit,
                             name = "通行证"
                         }
                     },
                     record = new
                     {
                         id = apply.ID,
                         outName = apply.OutName,
                         desc = apply.Desc,
                         credType = apply.CredType,
                         applyDate = apply.ApplyDate.ToString("yyyy/MM/dd"),
                         outUsers = db.User.Where(n => userIdList.Contains(n.ID)).Select(n => new
                         {
                             id = n.ID,
                             name = n.Name,
                             credNo = n.CredNo,
                             history = db.History.Where(m => m.ApplyId == apply.ID && m.UserId == n.ID).Select(m => new {
                                 id = m.ID,
                                 signNo = m.SignNo,
                                 signNation = m.SignNation,
                                 signTime = m.SignTime,
                                 isOut = m.IsOut
                             }).ToList()
                         }).ToList(),
                         applyAtt = db.Attachment.ToList().Where(m => apply.ApplyAtt.Split(',').Select(int.Parse).ToList().Contains(m.ID)).Select(m => new
                         {
                             id = m.ID,
                             name = m.Name,
                             url = Url.Action("Download", "Common", new { id = m.ID })
                         }),
                         outDate = new
                         {
                             show = true,
                             data = apply.OutDate == null ? "" : apply.OutDate.Value.ToString("yyyy/MM/dd")
                         },
                         signStatus = apply.SignStatus,
                         afterAtt = new
                         {
                             show = apply.AfterAtt != null,
                             data = apply.AfterAtt == null ? null : db.Attachment.ToList().Where(m => apply.AfterAtt.Split(',').Select(int.Parse).ToList().Contains(m.ID)).Select(m => new
                             {
                                 id = m.ID,
                                 name = m.Name,
                                 url = Url.Action("Download", "Common", new { id = m.ID })
                             })
                         }
                     }
                 }
             }));
         }
     }
 }
        public ActionResult DoAdd(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 当前用户
            var employee = (User.Identity as AppkizIdentity).Employee;
            // 出访日期
            DateTime outDate = new DateTime();
            // 履历IDs
            List <int> historyIdList = new List <int>();

            /*
             * 参数获取
             */
            // 组团名
            var outName = collection["outName"];
            // 任务描述
            var descn = collection["desc"];
            // 出访类型
            var credType = collection["credType"];
            // 出访人员履历
            var outUsers = collection["outUsers"];
            // 出访日期
            var outDateString = collection["outDate"];
            // 履历ID列表
            var historyIds = collection["historyIds"];

            /*
             * 参数校验
             */
            // 团组名
            if (string.IsNullOrEmpty(outName))
            {
                return(ResponseUtil.Error(400, "团组名不能为空"));
            }
            // 出访任务
            if (string.IsNullOrEmpty(descn))
            {
                return(ResponseUtil.Error(400, "任务描述不能为空"));
            }
            // 出访类型
            if (string.IsNullOrEmpty(credType))
            {
                return(ResponseUtil.Error(400, "出访类型不能为空"));
            }
            // 人员ID列表
            if (string.IsNullOrEmpty(outUsers))
            {
                return(ResponseUtil.Error(400, "出访人员不能为空"));
            }
            // 出访日期
            if (!string.IsNullOrEmpty(outDateString))
            {
                if (!DateTime.TryParse(outDateString, out outDate))
                {
                    return(ResponseUtil.Error(400, "出访日期格式不正确"));
                }
            }
            // 履历ID列表
            if (!string.IsNullOrEmpty(historyIds))
            {
                historyIdList = historyIds.Split(',').Select(int.Parse).ToList();
            }

            /*
             * 存储申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = new YGS_Apply();
                apply.OutName  = outName;
                apply.Desc     = descn;
                apply.UserId   = employee.EmplID;
                apply.CredType = credType;
                apply.OutUsers = outUsers;
                //apply.ApplyAtt = applyAtt;
                apply.ApplyStatus = WHConstants.Apply_Status_Passed;
                apply.ApplyDate   = DateTime.Now;
                apply.NextStep    = "";
                if (!string.IsNullOrEmpty(outDateString))
                {
                    apply.OutDate = outDate;
                }
                apply.CreateTime = DateTime.Now;
                apply.UpdateTime = DateTime.Now;
                apply.IsDelete   = true;
                db.Apply.Add(apply);
                db.SaveChanges();

                // 更新对应的履历
                if (historyIdList.Count > 0)
                {
                    var histories = db.History.Where(n => historyIdList.Contains(n.ID)).ToList();
                    foreach (var history in histories)
                    {
                        history.ApplyId = apply.ID;
                    }
                    db.SaveChanges();
                }

                return(ResponseUtil.OK(200, "创建成功"));
            }
        }
        public ActionResult DoUpdate(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 履历ID
            int id = 0;
            // 签证时间
            DateTime signTime = new DateTime();
            // 是否出行
            bool isOut = true;

            /*
             * 参数获取
             */
            // 履历ID
            var idString = collection["id"];
            // 签证号
            var signNo = collection["signNo"];
            // 签证地
            var signNation = collection["signNation"];
            // 签证时间
            var signTimeString = collection["signTime"];
            // 是否出行
            var isOutString = collection["isOut"];

            /*
             * 参数校验
             */
            // 履历ID
            if (string.IsNullOrEmpty(idString))
            {
                return(ResponseUtil.Error(400, "履历ID不能为空"));
            }
            else
            {
                if (!int.TryParse(idString, out id))
                {
                    return(ResponseUtil.Error(400, "履历ID格式不正确"));
                }
            }
            // 签证号
            if (string.IsNullOrEmpty(signNo))
            {
                return(ResponseUtil.Error(400, "签证号不能为空"));
            }
            // 签证时间
            if (!string.IsNullOrEmpty(signTimeString))
            {
                if (!DateTime.TryParse(signTimeString, out signTime))
                {
                    return(ResponseUtil.Error(400, "签证时间格式错误"));
                }
            }
            // 是否出行
            if (!string.IsNullOrEmpty(isOutString))
            {
                if (!bool.TryParse(isOutString, out isOut))
                {
                    return(ResponseUtil.Error(400, "是否出行格式不正确"));
                }
            }

            /*
             * 更新履历
             */
            using (var db = new YGSDbContext())
            {
                var history = db.History.Where(n => n.ID == id).FirstOrDefault();
                if (history == null)
                {
                    return(ResponseUtil.Error(400, "履历不存在"));
                }
                else
                {
                    history.SignNo = signNo;                    // 签证号
                    if (!string.IsNullOrEmpty(signTimeString))  // 签证时间
                    {
                        history.SignTime = signTime;
                    }
                    else
                    {
                        history.SignTime = null;
                    }
                    if (!string.IsNullOrEmpty(signNation))      // 签证地
                    {
                        history.SignNation = signNation;
                    }
                    else
                    {
                        history.SignNation = null;
                    }
                    if (!string.IsNullOrEmpty(isOutString))
                    {
                        history.IsOut = isOut;                      // 是否出行
                    }
                    else
                    {
                        history.IsOut = null;
                    }
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "履历更新成功"));
                }
            }
        }
        public ActionResult List(FormCollection collection)
        {
            /*
             * 变量定义
             */
            var    db     = new YGSDbContext();
            OrgMgr orgMgr = new OrgMgr();

            // 开始日期
            DateTime startDate = new DateTime();
            // 结束日期
            DateTime endDate = new DateTime();
            // 页数
            int page = WHConstants.Default_Page;
            // 分页大小
            int pageSize = WHConstants.Default_Page_Size;
            // 申请列表
            var applyList = db.Apply.Where(n => n.IsDelete == false);

            /*
             * 参数获取
             */
            // 开始日期
            var startDateString = collection["startDate"];
            // 结束日期
            var endDateString = collection["endDate"];
            // 状态
            var status = collection["status"];
            // 关键字
            var keyword = collection["keyword"];
            // 页数
            var pageString = collection["page"];
            // 分页大小
            var pageSizeString = collection["pageSize"];

            /*
             * 参数校验
             */
            // 验证开始日期
            if (!string.IsNullOrEmpty(startDateString))
            {
                if (DateTime.TryParse(startDateString, out startDate))
                {
                    applyList = applyList.Where(t => DbFunctions.TruncateTime(t.CreateTime) >= DbFunctions.TruncateTime(startDate));
                }
                else
                {
                    // 验证出错
                    return(ResponseUtil.Error(400, "开始日期错误"));
                }
            }

            // 验证结束日期
            if (!string.IsNullOrEmpty(endDateString))
            {
                if (DateTime.TryParse(endDateString, out endDate))
                {
                    applyList = applyList.Where(t => DbFunctions.TruncateTime(t.CreateTime) <= DbFunctions.TruncateTime(endDate));
                }
                else
                {
                    // 验证出错
                    return(ResponseUtil.Error(400, "结束日期错误"));
                }
            }
            // 验证状态
            if (string.IsNullOrEmpty(status))
            {
                return(ResponseUtil.Error(400, "验证状态不能为空"));
            }
            else
            {
                applyList = applyList.Where(n => n.ApplyStatus == status);
            }
            // 关键字
            if (!string.IsNullOrEmpty(keyword))
            {
                applyList = applyList.Where(n => n.OutName.Contains(keyword));
            }
            // 验证分页大小
            if (!string.IsNullOrEmpty(pageString))
            {
                if (int.TryParse(pageString, out page))
                {
                    if (page <= 0)
                    {
                        return(ResponseUtil.Error(400, "分页大小错误"));
                    }
                }
                else
                {
                    // 验证出错
                    return(ResponseUtil.Error(400, "分页大小错误"));
                }
            }
            // 验证页数
            if (!string.IsNullOrEmpty(pageSizeString))
            {
                if (int.TryParse(pageSizeString, out pageSize))
                {
                    if (pageSize <= 0)
                    {
                        return(ResponseUtil.Error(400, "页数错误"));
                    }
                }
                else
                {
                    // 验证出错
                    return(ResponseUtil.Error(400, "页数错误"));
                }
            }

            /*
             * 获取数据
             */
            // 记录总数
            var totalCount = applyList.Count();
            // 记录总页数
            var totalPage = (int)Math.Ceiling((float)totalCount / pageSize);
            // 查询结果数据
            var resultRecords = applyList.OrderByDescending(n => n.CreateTime).Skip((page - 1) * pageSize).Take(pageSize).ToList();

            //预约列表格式
            List <object> applys = new List <object>();

            foreach (var apply in resultRecords)
            {
                var applyEmployee = orgMgr.GetEmployee(apply.UserId);
                // 获得所有外出人员id
                var outUserIds = apply.OutUsers.Split(',').Select(int.Parse).ToList();
                applys.Add(new
                {
                    id        = apply.ID,
                    outName   = apply.OutName,
                    desc      = apply.Desc,
                    applyDate = apply.ApplyDate.ToString("yyyy/MM/dd"),
                    applyUser = applyEmployee == null ? null : string.Format("{0} {1}", applyEmployee.DeptName, applyEmployee.EmplName),
                    outUsers  = db.User.ToList().Where(m => outUserIds.Contains(m.ID)).Select(m => new
                    {
                        id     = m.ID,
                        name   = m.Name,
                        status = m.CredNo == null ? "fatal" : (db.Cred.Where(n => n.UserID == m.ID).Count() > 0 ? "normal" : "warn")
                    }),
                    checkOpinion = apply.CheckOpinion
                });
            }

            return(new JsonNetResult(new
            {
                code = 200,
                data = new
                {
                    records = applys,
                    meta = new
                    {
                        current_page = page,
                        total_page = totalPage,
                        current_count = (page - 1) * pageSize + resultRecords.ToList().Count(),
                        total_count = totalCount,
                        per_page = pageSize
                    }
                }
            }));
        }
        public ActionResult Add(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 用户ID
            int id = 0;

            /*
             * 参数获取
             */
            // 用户ID
            var userId = collection["userId"];

            /*
             * 参数校验
             */
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out id))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }

            var db   = new YGSDbContext();
            var user = db.User.Where(n => n.ID == id).FirstOrDefault();

            if (user == null)
            {
                return(ResponseUtil.Error(400, "用户不存在"));
            }
            else
            {
                return(new JsonNetResult(new
                {
                    code = 200,
                    data = new
                    {
                        credTypes = new object[]
                        {
                            new {
                                id = 1,
                                type = WHConstants.Cred_Type_Passport,
                                name = "护照"
                            },
                            new
                            {
                                id = 2,
                                type = WHConstants.Cred_Type_Permit,
                                name = "通行证"
                            }
                        },
                        user = new
                        {
                            id = user.ID,
                            name = user.Name,
                            credNo = user.CredNo
                        }
                    }
                }));
            }
        }
Exemple #23
0
        public ActionResult DoUpdate(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 申请ID
            int aid = 0;

            /*
             * 参数获取
             */
            // 申请ID
            var id = collection["id"];
            // 团组名
            var outName = collection["outName"];
            // 出访任务
            var descn = collection["desc"];
            // 出访类型
            var credType = collection["credType"];
            // 人员ID列表
            var outUsers = collection["outUsers"];
            // 申请附件ID列表
            var applyAtt = collection["applyAtt"];
            // 资料回传附件ID列表
            var afterAtt = collection["afterAtt"];

            /*
             * 参数校验
             */
            // 申请ID
            if (string.IsNullOrEmpty(id))
            {
                return(ResponseUtil.Error(400, "申请ID不能为空"));
            }
            else
            {
                if (!int.TryParse(id, out aid))
                {
                    return(ResponseUtil.Error(400, "申请ID不正确"));
                }
            }
            // 团组名
            if (string.IsNullOrEmpty(outName))
            {
                return(ResponseUtil.Error(400, "团组名不能为空"));
            }
            // 出访任务
            if (string.IsNullOrEmpty(descn))
            {
                return(ResponseUtil.Error(400, "出访类型不能为空"));
            }
            // 人员ID列表
            if (string.IsNullOrEmpty(outUsers))
            {
                return(ResponseUtil.Error(400, "出访人员不能为空"));
            }
            // 申请附件ID不能为空
            if (string.IsNullOrEmpty(applyAtt))
            {
                return(ResponseUtil.Error(400, "申请附件不能为空"));
            }

            /*
             * 查询申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = db.Apply.Where(n => n.ID == aid).FirstOrDefault();
                if (apply == null)
                {
                    return(ResponseUtil.Error(400, "申请不存在"));
                }
                else
                {
                    apply.OutName  = outName;
                    apply.Desc     = descn;
                    apply.CredType = credType;
                    apply.OutUsers = outUsers;
                    apply.ApplyAtt = applyAtt;
                    if (!string.IsNullOrEmpty(afterAtt))
                    {
                        apply.AfterAtt = afterAtt;
                    }
                    else
                    {
                        apply.AfterAtt = null;
                    }
                    // 如果当前申请是被拒绝,则重新到待审核中
                    if (apply.ApplyStatus == WHConstants.Apply_Status_Rejected)
                    {
                        apply.ApplyStatus = WHConstants.Apply_Status_Examing;

                        var notifyUserIdList = NotificationUtil.GetNotificationUsers();
                        foreach (var user in notifyUserIdList)
                        {
                            NotificationUtil.SendNotification(user, "您有新的出国申请审核", "/Apps/YGS/Home/Check");
                        }
                    }
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "申请更新成功"));
                }
            }
        }
Exemple #24
0
        public ActionResult List(FormCollection collection)
        {
            using (var db = new YGSDbContext())
            {
                /*
                 * 变量定义
                 */
                var    employee = (User.Identity as AppkizIdentity).Employee;
                OrgMgr orgMgr   = new OrgMgr();

                // 页数
                int page = WHConstants.Default_Page;
                // 分页大小
                int pageSize = WHConstants.Default_Page_Size;
                // 申请数据
                var applyList = db.Apply.Where(n => n.UserId == employee.EmplID && n.IsDelete == false);

                /*
                 * 参数获取
                 */
                // 申请单状态
                var status = collection["status"];
                // 关键字
                var keyword = collection["keyword"];
                // 页数
                var pageString = collection["page"];
                // 分页大小
                var pageSizeString = collection["pageSize"];

                /*
                 * 参数校验
                 */
                // 验证状态
                if (string.IsNullOrEmpty(status))
                {
                    return(ResponseUtil.Error(400, "状态不能为空"));
                }
                else
                {
                    applyList = applyList.Where(n => n.ApplyStatus == status);
                }
                // 关键字
                if (!string.IsNullOrEmpty(keyword))
                {
                    applyList = applyList.Where(n => n.OutName.Contains(keyword));
                }
                // 验证分页大小
                if (!string.IsNullOrEmpty(pageString))
                {
                    if (int.TryParse(pageString, out page))
                    {
                        if (page <= 0)
                        {
                            return(ResponseUtil.Error(400, "分页大小错误"));
                        }
                    }
                    else
                    {
                        // 验证出错
                        return(ResponseUtil.Error(400, "分页大小错误"));
                    }
                }
                // 验证页数
                if (!string.IsNullOrEmpty(pageSizeString))
                {
                    if (int.TryParse(pageSizeString, out pageSize))
                    {
                        if (pageSize <= 0)
                        {
                            return(ResponseUtil.Error(400, "页数错误"));
                        }
                    }
                    else
                    {
                        // 验证出错
                        return(ResponseUtil.Error(400, "页数错误"));
                    }
                }

                /*
                 * 查询申请
                 */
                // 记录总数
                var totalCount = applyList.Count();
                // 记录总页数
                var totalPage = (int)Math.Ceiling((float)totalCount / pageSize);
                // 查询结果数据
                var resultRecords = applyList.OrderByDescending(n => n.CreateTime).Skip((page - 1) * pageSize).Take(pageSize).ToList();

                //预约列表格式
                List <object> applys = new List <object>();

                // 履历表
                foreach (var apply in resultRecords)
                {
                    var applyEmployee = orgMgr.GetEmployee(apply.UserId);
                    // 获得所有外出人员id
                    var historyIdList = apply.OutUsers.Split(',').Select(int.Parse).ToList();

                    applys.Add(new
                    {
                        id        = apply.ID,
                        outName   = apply.OutName,
                        desc      = apply.Desc,
                        applyDate = apply.ApplyDate.ToString("yyyy/MM/dd"),
                        applyUser = applyEmployee == null ? null : string.Format("{0} {1}", applyEmployee.DeptName, applyEmployee.EmplName),
                        outUsers  = db.User.ToList().Where(m => historyIdList.Contains(m.ID)).Select(m => new
                        {
                            id   = m.ID,
                            name = m.Name
                        }).ToList(),
                        checkOpinion = apply.CheckOpinion,
                        nextStep     = apply.ApplyStatus == WHConstants.Apply_Status_Examing ? "等待领导审批" : (apply.ApplyStatus == WHConstants.Apply_Status_Passed ? "下载并填写表格" : "修改并重新提交审核")
                    });
                }

                return(new JsonNetResult(new
                {
                    code = 200,
                    data = new
                    {
                        records = applys,
                        meta = new
                        {
                            current_page = page,
                            total_page = totalPage,
                            current_count = (page - 1) * pageSize + resultRecords.ToList().Count(),
                            total_count = totalCount,
                            per_page = pageSize
                        }
                    }
                }));
            }
        }
        public ActionResult Delete(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 申请ID
            int aid = 0;
            // 用户ID
            int uid = 0;

            /*
             * 参数获取
             */
            // 申请ID
            var applyId = collection["applyId"];
            // 用户ID
            var userId = collection["userId"];

            /*
             * 参数校验
             */
            // 申请ID
            if (string.IsNullOrEmpty(applyId))
            {
                return(ResponseUtil.Error(400, "申请ID不能为空"));
            }
            else
            {
                if (!int.TryParse(applyId, out aid))
                {
                    return(ResponseUtil.Error(400, "申请ID不正确"));
                }
            }
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out uid))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }

            /*
             * 将userId用户从申请的出国人员中去掉
             */
            using (var db = new YGSDbContext())
            {
                var apply = db.Apply.Where(n => n.ID == aid).FirstOrDefault();
                if (apply == null)
                {
                    return(ResponseUtil.Error(400, "申请不存在"));
                }
                else
                {
                    // 原有的outUsers
                    var oldOutUsers = apply.OutUsers.Split(',').ToList().Select(int.Parse).ToList();
                    // 最新的outUsers
                    var currentOutUsers = new List <int>();

                    // 获得筛选掉的用户,并移除
                    foreach (int outUid in oldOutUsers)
                    {
                        if (outUid != uid)
                        {
                            currentOutUsers.Add(outUid);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    // 判断是否还有出国人员
                    if (currentOutUsers.Count == 0)
                    {
                        db.Apply.Remove(apply);
                        db.SaveChanges();
                    }
                    else
                    {
                        var finalOutUsers = string.Join(",", currentOutUsers);
                        apply.OutUsers = finalOutUsers;
                        db.SaveChanges();
                    }

                    return(ResponseUtil.Error(200, "删除成功"));
                }
            }
        }
        public ActionResult DoUpdate(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 申请ID
            int aid = 0;
            // 用户ID
            int id = 0;
            // 性别
            int sex = 0;
            // 出生日期
            DateTime birthday = new DateTime();

            /*
             * 参数获取
             */
            // 申请ID
            var applyId = collection["aid"];
            // 用户ID
            var userId = collection["id"];
            // 姓名
            var name = collection["name"];
            // 性别
            var sexString = collection[@"sex"];
            // 出生地
            var location = collection["location"];
            // 出生日期
            var birthDay = collection["birthDay"];
            // 身份证号
            var credNo = collection["credNo"];
            // 工作单位
            var unit = collection["unit"];
            // 工作部门
            var depart = collection["depart"];
            // 级别
            var level = collection["level"];
            // 职务
            var duty = collection["duty"];

            /*
             * 参数校验
             */
            // 申请ID
            if (!string.IsNullOrEmpty(applyId))
            {
                if (!int.TryParse(applyId, out aid))
                {
                    return(ResponseUtil.Error(400, "申请ID不正确"));
                }
            }
            // 用户ID
            if (string.IsNullOrEmpty(userId))
            {
                return(ResponseUtil.Error(400, "用户ID不能为空"));
            }
            else
            {
                if (!int.TryParse(userId, out id))
                {
                    return(ResponseUtil.Error(400, "用户ID不正确"));
                }
            }
            // 姓名
            if (string.IsNullOrEmpty(name))
            {
                return(ResponseUtil.Error(400, "姓名不能为空"));
            }
            // 性别
            if (!string.IsNullOrEmpty(sexString))
            {
                if (int.TryParse(sexString, out sex))
                {
                    if (sex != 0 && sex != 1)
                    {
                        return(ResponseUtil.Error(400, "性别错误"));
                    }
                }
                else
                {
                    return(ResponseUtil.Error(400, "性别错误"));
                }
            }
            // 出生地
            //if (string.IsNullOrEmpty(location))
            //{
            //    return ResponseUtil.Error(400, "出生地不能为空");
            //}
            // 出生日期
            if (!string.IsNullOrEmpty(birthDay))
            {
                if (!DateTime.TryParse(birthDay, out birthday))
                {
                    return(ResponseUtil.Error(400, "出生日期无效"));
                }
            }
            // 身份证号
            if (!string.IsNullOrEmpty(credNo))
            {
                // 校验身份证格式
                if ((!Regex.IsMatch(credNo, @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$", RegexOptions.IgnoreCase)))
                {
                    return(ResponseUtil.Error(400, "身份证格式不正确"));
                }
            }
            // 工作单位
            //if (string.IsNullOrEmpty(unit))
            //{
            //    return ResponseUtil.Error(400, "工作单位不能为空");
            //}
            // 工作部门
            //if (string.IsNullOrEmpty(depart))
            //{
            //    return ResponseUtil.Error(400, "工作部门不能为空");
            //}
            // 级别
            //if (string.IsNullOrEmpty(level))
            //{
            //    return ResponseUtil.Error(400, "级别不能为空");
            //}
            // 职务
            //if (string.IsNullOrEmpty(duty))
            //{
            //    return ResponseUtil.Error(400, "职务不能为空");
            //}

            /*
             * 更新用户信息
             */
            using (var db = new YGSDbContext())
            {
                var user = db.User.Where(n => n.ID == id).FirstOrDefault();
                if (user == null)
                {
                    return(ResponseUtil.Error(400, "用户不存在"));
                }
                else
                {
                    var credUser = db.User.Where(n => n.CredNo == credNo && !string.IsNullOrEmpty(credNo)).FirstOrDefault();

                    if (credUser != null)
                    {
                        if (credUser.Name != user.Name)
                        {
                            return(ResponseUtil.Error(400, "相同身份证号用户已存在"));
                        }
                        else
                        {
                            if (credUser.ID == user.ID)
                            {
                                // 同一个用户
                                user.Name     = name;
                                user.Sex      = sex;
                                user.Location = location;
                                if (string.IsNullOrEmpty(birthDay))
                                {
                                    user.BirthDay = null;
                                }
                                else
                                {
                                    user.BirthDay = birthday;
                                }
                                user.CredNo     = credNo;
                                user.Unit       = unit;
                                user.Depart     = depart;
                                user.Level      = level;
                                user.Duty       = duty;
                                user.UpdateTime = DateTime.Now;
                                db.SaveChanges();
                                return(new JsonNetResult(new
                                {
                                    code = 200,
                                    data = new
                                    {
                                        id = user.ID
                                    }
                                }));
                            }
                            else
                            {
                                // 不同用户,同一个名字和身份号,则需要用原有的用户替换现有的用户
                                // 2中情况:
                                // 1. 从审核列表中点击进来,需要替换对应的审核中【外出人员】和对应履历表中【人员ID】
                                // 2. 从人员管理中点击进来,表明该用户已经具有身份证信息,这种情况下说明用户冲突
                                if (string.IsNullOrEmpty(applyId))
                                {
                                    return(ResponseUtil.Error(400, "相同身份证号用户已存在"));
                                }
                                else
                                {
                                    return(new JsonNetResult(new
                                    {
                                        code = 200,
                                        data = new
                                        {
                                            id = credUser.ID
                                        }
                                    }));
                                }
                            }
                        }
                    }
                    else
                    {
                        // 同一个用户
                        user.Name     = name;
                        user.Sex      = sex;
                        user.Location = location;
                        if (string.IsNullOrEmpty(birthDay))
                        {
                            user.BirthDay = null;
                        }
                        else
                        {
                            user.BirthDay = birthday;
                        }
                        user.CredNo     = credNo;
                        user.Unit       = unit;
                        user.Depart     = depart;
                        user.Level      = level;
                        user.Duty       = duty;
                        user.UpdateTime = DateTime.Now;
                        db.SaveChanges();
                        return(new JsonNetResult(new
                        {
                            code = 200,
                            data = new
                            {
                                id = user.ID
                            }
                        }));
                    }
                }
            }
        }
        public ActionResult DoUpdate(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 申请ID
            int aid = 0;
            // 出访日期
            DateTime outDate = new DateTime();

            /*
             * 参数获取
             */
            // 申请ID
            var id = collection["id"];
            // 出访日期
            var outDateString = collection["outDate"];
            // 签证情况
            var signStatus = collection["signStatus"];
            // 履历ID列表
            var outUsers = collection["outUsers"];

            /*
             * 参数校验
             */
            // 申请ID
            if (string.IsNullOrEmpty(id))
            {
                return(ResponseUtil.Error(400, "申请ID不能为空"));
            }
            else
            {
                if (!int.TryParse(id, out aid))
                {
                    return(ResponseUtil.Error(400, "申请ID不正确"));
                }
            }
            // 出访日期
            //if(string.IsNullOrEmpty(outDateString))
            //{
            //    return ResponseUtil.Error(400, "出访日期不能为空");
            //}
            //else
            //{
            //    if(!DateTime.TryParse(outDateString, out outDate))
            //    {
            //        return ResponseUtil.Error(400, "出访日期格式不正确");
            //    }
            //}
            if (!string.IsNullOrEmpty(outDateString))
            {
                if (!DateTime.TryParse(outDateString, out outDate))
                {
                    return(ResponseUtil.Error(400, "出访日期格式不正确"));
                }
            }

            // 履历ID列表
            if (string.IsNullOrEmpty(outUsers))
            {
                return(ResponseUtil.Error(400, "出访人员不能为空"));
            }

            /*
             * 更新申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = db.Apply.Where(n => n.ID == aid).FirstOrDefault();
                if (apply == null)
                {
                    return(ResponseUtil.Error(400, "申请不能为空"));
                }
                else
                {
                    // 原有的outUsers
                    //var oldOutUsers = apply.OutUsers.Split(',').ToList().Select(int.Parse).ToList();
                    // 最新的outUsers
                    //var currentOutUsers = outUsers.Split(',').ToList().Select(int.Parse).ToList();
                    // 获得筛选掉的用户,并移除
                    //foreach(int outUid in oldOutUsers)
                    //{
                    //    if (!currentOutUsers.Contains(outUid))
                    //    {
                    //        var deleteUser = db.User.Where(n => n.ID == outUid).FirstOrDefault();
                    //        if(deleteUser != null)
                    //        {
                    //            db.User.Remove(deleteUser);
                    //        }
                    //    }
                    //}
                    if (!string.IsNullOrEmpty(outDateString))
                    {
                        apply.OutDate = outDate;
                    }
                    else
                    {
                        apply.OutDate = null;
                    }
                    apply.SignStatus = signStatus;
                    apply.OutUsers   = outUsers;
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "更新成功"));
                }
            }
        }
        public ActionResult DoAdd(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 性别
            int sex = 0;
            // 出生日期
            DateTime birthday = new DateTime();

            /*
             * 参数获取
             */
            // 姓名
            var name = collection["name"];
            // 性别
            var sexString = collection[@"sex"];
            // 出生地
            var location = collection["location"];
            // 出生日期
            var birthDay = collection["birthDay"];
            // 身份证号
            var credNo = collection["credNo"];
            // 工作单位
            var unit = collection["unit"];
            // 工作部门
            var depart = collection["depart"];
            // 级别
            var level = collection["level"];
            // 职务
            var duty = collection["duty"];

            /*
             * 参数校验
             */
            // 姓名
            if (string.IsNullOrEmpty(name))
            {
                return(ResponseUtil.Error(400, "姓名不能为空"));
            }
            // 性别
            if (!string.IsNullOrEmpty(sexString))
            {
                if (int.TryParse(sexString, out sex))
                {
                    if (sex != 0 && sex != 1)
                    {
                        return(ResponseUtil.Error(400, "性别错误"));
                    }
                }
                else
                {
                    return(ResponseUtil.Error(400, "性别错误"));
                }
            }
            // 出生地
            //if (string.IsNullOrEmpty(location))
            //{
            //    return ResponseUtil.Error(400, "出生地不能为空");
            //}
            // 出生日期
            if (!string.IsNullOrEmpty(birthDay))
            {
                if (!DateTime.TryParse(birthDay, out birthday))
                {
                    return(ResponseUtil.Error(400, "出生日期无效"));
                }
            }
            // 身份证号
            if (!string.IsNullOrEmpty(credNo))
            {
                // 校验身份证格式
                if ((!Regex.IsMatch(credNo, @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$", RegexOptions.IgnoreCase)))
                {
                    return(ResponseUtil.Error(400, "身份证格式不正确"));
                }
            }
            // 工作单位
            //if (string.IsNullOrEmpty(unit))
            //{
            //    return ResponseUtil.Error(400, "工作单位不能为空");
            //}
            // 工作部门
            //if (string.IsNullOrEmpty(depart))
            //{
            //    return ResponseUtil.Error(400, "工作部门不能为空");
            //}
            // 级别
            //if (string.IsNullOrEmpty(level))
            //{
            //    return ResponseUtil.Error(400, "级别不能为空");
            //}
            // 职务
            //if (string.IsNullOrEmpty(duty))
            //{
            //    return ResponseUtil.Error(400, "职务不能为空");
            //}

            /*
             * 添加用户
             */
            using (var db = new YGSDbContext())
            {
                var user = db.User.Where(n => n.CredNo == credNo && !string.IsNullOrEmpty(credNo)).FirstOrDefault();
                if (user == null)
                {
                    user      = new YGS_User();
                    user.Name = name;
                    if (!string.IsNullOrEmpty(sexString))
                    {
                        user.Sex = sex;
                    }
                    if (!string.IsNullOrEmpty(location))
                    {
                        user.Location = location;
                    }
                    if (!string.IsNullOrEmpty(birthDay))
                    {
                        user.BirthDay = birthday;
                    }
                    if (!string.IsNullOrEmpty(credNo))
                    {
                        user.CredNo = credNo;
                    }
                    if (!string.IsNullOrEmpty(unit))
                    {
                        user.Unit = unit;
                    }
                    if (!string.IsNullOrEmpty(depart))
                    {
                        user.Depart = depart;
                    }
                    if (!string.IsNullOrEmpty(level))
                    {
                        user.Level = level;
                    }
                    if (!string.IsNullOrEmpty(duty))
                    {
                        user.Duty = duty;
                    }
                    user.CreateTime = DateTime.Now;
                    user.UpdateTime = DateTime.Now;
                    db.User.Add(user);
                    db.SaveChanges();

                    return(ResponseUtil.OK(200, "创建成功!"));
                }
                else
                {
                    return(ResponseUtil.Error(400, "用户已存在"));
                }
            }
        }
Exemple #29
0
        public ActionResult DoAdd(FormCollection collection)
        {
            /*
             * 变量定义
             */
            // 当前用户
            var employee = (User.Identity as AppkizIdentity).Employee;

            /*
             * 参数获取
             */
            // 组团名
            var outName = collection["outName"];
            // 任务描述
            var descn = collection["desc"];
            // 出访类型
            var credType = collection["credType"];
            // 出访人员履历
            var outUsers = collection["outUsers"];
            // 申请附件
            var applyAtt = collection["applyAtt"];

            /*
             * 参数校验
             */
            // 团组名
            if (string.IsNullOrEmpty(outName))
            {
                return(ResponseUtil.Error(400, "团组名不能为空"));
            }
            // 出访任务
            if (string.IsNullOrEmpty(descn))
            {
                return(ResponseUtil.Error(400, "任务描述不能为空"));
            }
            // 出访类型
            if (string.IsNullOrEmpty(credType))
            {
                return(ResponseUtil.Error(400, "出访类型不能为空"));
            }
            // 人员ID列表
            if (string.IsNullOrEmpty(outUsers))
            {
                return(ResponseUtil.Error(400, "出访人员不能为空"));
            }
            // 申请附件ID不能为空
            if (string.IsNullOrEmpty(applyAtt))
            {
                return(ResponseUtil.Error(400, "申请附件不能为空"));
            }

            /*
             * 存储申请
             */
            using (var db = new YGSDbContext())
            {
                var apply = new YGS_Apply();
                apply.OutName     = outName;
                apply.Desc        = descn;
                apply.UserId      = employee.EmplID;
                apply.CredType    = credType;
                apply.OutUsers    = outUsers;
                apply.ApplyAtt    = applyAtt;
                apply.ApplyStatus = WHConstants.Apply_Status_Examing;
                apply.ApplyDate   = DateTime.Now;
                apply.NextStep    = "下载并填写表格";
                apply.CreateTime  = DateTime.Now;
                apply.UpdateTime  = DateTime.Now;
                apply.IsDelete    = false;
                db.Apply.Add(apply);
                db.SaveChanges();

                var notifyUserIdList = NotificationUtil.GetNotificationUsers();

                foreach (var user in notifyUserIdList)
                {
                    NotificationUtil.SendNotification(user, "您有新的出国申请审核", "/Apps/YGS/Home/Check");
                }

                return(ResponseUtil.OK(200, "创建成功"));
            }
        }
        public ActionResult DoAddTempUser(FormCollection collection)
        {
            /*
             * 参数获取
             */
            // 姓名
            var name = collection["name"];
            // 身份证号
            var credNo = collection["credNo"];

            /*
             * 参数校验
             */
            // 姓名
            if (string.IsNullOrEmpty(name))
            {
                return(ResponseUtil.Error(400, "姓名不能为空"));
            }

            /*
             * 查询重复
             */
            using (var db = new YGSDbContext())
            {
                // 身份证号
                if (string.IsNullOrEmpty(credNo))
                {
                    // 身份证号为空,说明只填写了姓名,直接建立新用户,返回新用户ID给前端
                    var user = new YGS_User();
                    user.Name       = name;
                    user.CreateTime = DateTime.Now;

                    db.User.Add(user);
                    db.SaveChanges();

                    return(new JsonNetResult(new
                    {
                        code = 200,
                        data = new
                        {
                            id = user.ID
                        }
                    }));
                }
                else
                {
                    // 校验身份证格式
                    if ((!Regex.IsMatch(credNo, @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$", RegexOptions.IgnoreCase)))
                    {
                        return(ResponseUtil.Error(400, "身份证格式不正确"));
                    }
                    // 输入了身份证号,则进行校验,身份信息是否正确。
                    // 如果身份证与姓名一致,则返回用户ID,如果不正确,则该用户已存在,输入身份证重复
                    var user = db.User.Where(n => n.CredNo == credNo).FirstOrDefault();
                    if (user == null)
                    {
                        user            = new YGS_User();
                        user.Name       = name;
                        user.CredNo     = credNo;
                        user.CreateTime = DateTime.Now;

                        db.User.Add(user);
                        db.SaveChanges();

                        return(new JsonNetResult(new
                        {
                            code = 200,
                            data = new
                            {
                                id = user.ID
                            }
                        }));
                    }
                    else
                    {
                        if (user.Name == name)
                        {
                            return(new JsonNetResult(new
                            {
                                code = 200,
                                data = new
                                {
                                    id = user.ID
                                }
                            }));
                        }
                        else
                        {
                            // 不同人,同身份证
                            return(ResponseUtil.Error(400, "已存在身份证相同的其他用户"));
                        }
                    }
                }
            }
        }