public BaseResultEntity Post(ProjectEntity Project)
 {
     Logger.LogDebug("AddProject Request:" + JsonHelper.SerializeObject(Project), "AddProjectController", "Post");
     BaseResultEntity ret = new BaseResultEntity();
     try
     {
         var _existProject = _projectBLL.GetModels(x => x.Number == Project.Number || x.Name == Project.Name).ToList();
         if (_existProject == null || _existProject.Count() == 0)
         {
             var _area = _areaBLL.GetModels(x => x.Name == Project.ProjectArea).FirstOrDefault();
             if (_area != null && _area.ID != 0)
             {
                 if (!string.IsNullOrWhiteSpace(Project.Number) && !string.IsNullOrWhiteSpace(Project.Name))
                 {
                     var _newProject = new Project()
                     {
                         Number = Project.Number,
                         Name = Project.Name,
                         //Address = Project.Address,
                         Address = "",
                         AreaID = _area.ID,
                         DevelopCompany = Project.DevelopCompany,
                         IdentityNumber = Project.IdentityNumber,
                         CreateTime = DateTime.Now,
                         LastUpdate = DateTime.Now,
                         IsEnd = false,
                         EndReason = null
                     };
                     _projectBLL.Add(_newProject);
                     ret.Code = 0;
                     ret.ErrMsg = "";
                 }
                 else
                 {
                     ret.Code = 102;
                     ret.ErrMsg = "创建项目的编号/名称不允许为空!";
                 }
             }
             else
             {
                 ret.Code = 103;
                 ret.ErrMsg = "项目所属区域不存在!";
             }
         }
         else
         {
             ret.Code = 101;
             ret.ErrMsg = "创建项目的编号/名称已经存在!";
         }
     }
     catch (Exception ex)
     {
         Logger.LogException("创建项目发生异常!", "AddProjectController", "Post", ex);
         ret.Code = 999;
         ret.ErrMsg = ex.Message;
     }
     return ret;
 }
        public GetAreaListResultEntity Post(GetAreaListRequestModel req)
        {
            Logger.LogDebug("GetAreaList Request:" + JsonHelper.SerializeObject(req), "GetAreaListController", "Post");
            GetAreaListResultEntity ret = new GetAreaListResultEntity()
            {
                Code     = 0,
                ErrMsg   = "",
                AreaList = new List <AreaEntity>()
            };

            try
            {
                bool cityNameIsEmtpy = string.IsNullOrEmpty(req.CityName);
                var  _hs             = new List <Area>();

                if (cityNameIsEmtpy)
                {
                    _hs = _areaBLL.GetModels(a => a.ID > 0).ToList();
                }
                else
                {
                    _hs = _areaBLL.GetModels(a => a.CityName == req.CityName).ToList();
                }

                if (_hs != null && _hs.Count > 0)
                {
                    _hs.ForEach(a =>
                    {
                        var areaInfo      = new AreaEntity();
                        areaInfo.ID       = a.ID;
                        areaInfo.Name     = a.Name;
                        areaInfo.CityName = a.CityName;
                        ret.AreaList.Add(areaInfo);
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("获取区域列表时发生异常!", "GetAreaListController", "Post", ex);
                ret.Code   = 999;
                ret.ErrMsg = ex.Message;
            }
            return(ret);
        }
        public GetProjectsByAreaResultEntity Post(GetProjectsByAreaRequestModel req)
        {
            Logger.LogDebug("GetProjectsByArea Request:" + JsonHelper.SerializeObject(req), "GetProjectsByAreaController", "Post");
            GetProjectsByAreaResultEntity ret = new GetProjectsByAreaResultEntity
            {
                Code     = 0,
                ErrMsg   = "",
                Projects = new List <ProjectEntity>()
            };

            try
            {
                var _projects = new List <Project>();

                if (req.AreaId > 0)
                {
                    _projects = _projectBLL.GetModels(p => p.AreaID == req.AreaId).ToList();
                }
                else
                {
                    _projects = _projectBLL.GetModels(p => p.ID > 0).ToList();
                }

                if (_projects == null || _projects.Count == 0)
                {
                    ret.Code   = 405;
                    ret.ErrMsg = "没有查询到对应的项目信息。";
                }
                else
                {
                    var areaIds = _projects.Select(p => p.AreaID).Distinct().ToList();
                    var areaDic = new Dictionary <int, string>();
                    areaIds.ForEach(i =>
                    {
                        var areaInfo = _areaBLL.GetModels(a => a.ID == i).FirstOrDefault();
                        if (areaInfo == null)
                        {
                            Logger.LogWarning(string.Format("无法查询到ID为{0}的地区区域信息!请确认数据是否正确!", i), "FetProjectsByAreaController", "Post");
                        }
                        else
                        {
                            areaDic.Add(i, areaInfo.Name);
                        }
                    });

                    _projects.ForEach(p =>
                    {
                        var areaName = string.Empty;
                        areaDic.TryGetValue(p.AreaID, out areaName);

                        var project = new ProjectEntity
                        {
                            ID             = p.ID,
                            Address        = p.Address,
                            Name           = p.Name,
                            Number         = p.Number,
                            ProjectArea    = areaName,
                            IsEnd          = p.IsEnd,
                            EndReason      = p.EndReason,
                            IdentityNumber = p.IdentityNumber,
                            DevelopCompany = p.DevelopCompany
                        };

                        ret.Projects.Add(project);
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("获取项目列表时发生异常!", "GetProjectsByAreaController", "Post", ex);
                ret.Code   = 999;
                ret.ErrMsg = ex.Message;
            }
            return(ret);
        }
示例#4
0
        public BaseResultEntity Post(ProjectEntity req)
        {
            var ret = new BaseResultEntity()
            {
                Code   = 0,
                ErrMsg = ""
            };

            try
            {
                var _existProject = _projectBLL.GetModels(x => x.ID == req.ID).FirstOrDefault();
                if (_existProject == null)
                {
                    ret.Code   = 104;
                    ret.ErrMsg = "修改项目的ID不存在!";
                }
                else if (_existProject.IsEnd)
                {
                    ret.Code   = 105;
                    ret.ErrMsg = "已经结束的项目不允许修改!";
                }
                else
                {
                    if (_projectBLL.GetModels(x => (x.Number == req.Number || x.Name == req.Name) && x.ID != req.ID).FirstOrDefault() != null)
                    {
                        ret.Code   = 106;
                        ret.ErrMsg = "修改项目的编号/名称已经存在!";
                    }
                    else
                    {
                        var _area = _areaBLL.GetModels(x => x.Name == req.ProjectArea).FirstOrDefault();
                        if (_area != null && _area.ID != 0)
                        {
                            if (!string.IsNullOrWhiteSpace(req.Number) && !string.IsNullOrWhiteSpace(req.Name))
                            {
                                _existProject.Number         = req.Number;
                                _existProject.Name           = req.Name;
                                _existProject.Address        = "";
                                _existProject.AreaID         = _area.ID;
                                _existProject.DevelopCompany = req.DevelopCompany;
                                _existProject.IdentityNumber = req.IdentityNumber;
                                _existProject.LastUpdate     = DateTime.Now;
                                _existProject.IsEnd          = false;
                                _existProject.EndReason      = null;
                                _projectBLL.Update(_existProject);
                            }
                            else
                            {
                                ret.Code   = 102;
                                ret.ErrMsg = "修改项目的编号/名称不允许为空!";
                            }
                        }
                        else
                        {
                            ret.Code   = 103;
                            ret.ErrMsg = "项目所属区域不存在!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("修改项目时发生异常!", "EditProjectController", "Post", ex);
                ret.Code   = 999;
                ret.ErrMsg = ex.Message;
            }
            return(ret);
        }