Ejemplo n.º 1
0
        public IActionResult Add(DTOSaveVersionInfo dto)
        {
            var result = new ReturnResponse();

            CheckVersionInfo(dto);
            using (var unitOfWork = new UnitOfWork(DbContext))
            {
                if (unitOfWork.VersionInfoRepository.IsExist(o => o.VersionNo == dto.VersionNo && !o.IsDelete))
                {
                    throw new CustomExecption("9999", $"已经存在版本号为{dto.VersionNo}的版本信息");
                }
                var model = new Prc_VersionInfo();
                model.ID              = Guid.NewGuid();
                model.VersionNo       = dto.VersionNo;
                model.PublishDate     = Convert.ToDateTime(dto.PublishDate).RemoveMilliSecond();
                model.IsPublish       = false;
                model.Context         = Encoding.UTF8.GetBytes(dto.Content);
                model.LastOperateUser = LoginUserInfo.CurrUser.LoginName;
                model.LastUpdateTime  = DateTime.Now.RemoveMilliSecond();
                model.IsDelete        = false;
                unitOfWork.VersionInfoRepository.Add(model);
                OperateLoger.Write(LoginUserInfo.CurrUser.UserName, DateTime.Now, "新增版本【" + dto.VersionNo + "】");
                unitOfWork.SaveChanges();
            }

            return(Json(result));
        }
Ejemplo n.º 2
0
        private void CheckVersionInfo(DTOSaveVersionInfo dto)
        {
            string errorCode = "9999";

            if (string.IsNullOrWhiteSpace(dto.VersionNo))
            {
                throw new CustomExecption(errorCode, "版本号不能为空");
            }
            var regExp = new Regex(@"^[0-9]{2}.[0-9]{1}.[0-9]{4}$");

            if (!regExp.IsMatch(dto.VersionNo))
            {
                throw new CustomExecption(errorCode, "版本号格式不正确,格式必须类似于10.1.1001");
            }
            if (string.IsNullOrWhiteSpace(dto.PublishDate))
            {
                throw new CustomExecption(errorCode, "对外发布日期不能为空");
            }
            DateTime date = DateTime.Now;

            if (!DateTime.TryParse(dto.PublishDate, out date))
            {
                throw new CustomExecption(errorCode, "对外发布日期格式不正确");
            }
            if (string.IsNullOrWhiteSpace(dto.Content))
            {
                throw new CustomExecption(errorCode, "版本说明不能为空");
            }
            byte[] bytes = Encoding.UTF8.GetBytes(dto.Content);
            if (bytes.Length > 2 * 1024 * 1024)
            {
                throw new CustomExecption(errorCode, "版本说明大小不能超过2M");
            }
            if (!string.IsNullOrEmpty(dto.ID))
            {
                Guid id = Guid.Empty;
                if (!Guid.TryParse(dto.ID, out id))
                {
                    throw new CustomExecption(errorCode, "ID的格式不正确");
                }
            }
        }
Ejemplo n.º 3
0
        public IActionResult Edit(DTOSaveVersionInfo dto)
        {
            CheckVersionInfo(dto);
            if (string.IsNullOrWhiteSpace(dto.ID))
            {
                throw new CustomExecption("9999", "ID不能为空");
            }
            ReturnResponse result = new ReturnResponse();

            using (var unitOfWork = new UnitOfWork(DbContext))
            {
                var model = unitOfWork.VersionInfoRepository.Get(o => o.ID == Guid.Parse(dto.ID) && !o.IsDelete);
                if (model == null)
                {
                    throw new CustomExecption("9999", "获取版本信息失败");
                }
                if (unitOfWork.VersionInfoRepository.IsExist(o => o.VersionNo == dto.VersionNo && o.ID != model.ID && !o.IsDelete))
                {
                    throw new CustomExecption("9999", $"已经存在版本号为{dto.VersionNo}的版本信息");
                }
                model.VersionNo       = dto.VersionNo;
                model.PublishDate     = Convert.ToDateTime(dto.PublishDate).RemoveMilliSecond();
                model.Context         = Encoding.UTF8.GetBytes(dto.Content);
                model.LastOperateUser = LoginUserInfo.CurrUser.LoginName;
                model.LastUpdateTime  = DateTime.Now.RemoveMilliSecond();
                if (model.IsPublish)
                {
                    // 如果是已发布的,则取消发布
                    model.IsPublish = false;
                }
                unitOfWork.VersionInfoRepository.Update(model);

                unitOfWork.SaveChanges();
            }

            return(Json(result));
        }