コード例 #1
0
        public ValidationData ValidateUpdateDefectType(ClaimsPrincipal principal,
                                                       DefectType entity, UpdateDefectTypeModel model)
        {
            var validationData = new ValidationData();

            if (string.IsNullOrWhiteSpace(model.Code))
            {
                validationData.Fail("Defect code must not be null", Constants.AppResultCode.FailValidation);
            }
            else if (DefectTypes.Exists(model.Code))
            {
                validationData.Fail("Defect code existed", Constants.AppResultCode.FailValidation);
            }
            if (string.IsNullOrWhiteSpace(model.QCMappingCode))
            {
                validationData.Fail("QC Defect code must not be null", Constants.AppResultCode.FailValidation);
            }
            else if (DefectTypes.ExistsQCMappingCode(model.QCMappingCode))
            {
                validationData.Fail("QC Defect code existed", Constants.AppResultCode.FailValidation);
            }
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                validationData.Fail("Name must not be null", Constants.AppResultCode.FailValidation);
            }
            return(validationData);
        }
コード例 #2
0
        public IActionResult Update(int id, UpdateDefectTypeModel model)
        {
            var entity = _service.DefectTypes.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateDefectType(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            _service.UpdateDefectType(entity, model);
            context.SaveChanges();
            // must be in transaction
            var ev = _ev_service.UpdateDefectType(entity, User);

            context.SaveChanges();
            return(NoContent());
        }
コード例 #3
0
 public void UpdateDefectType(DefectType entity, UpdateDefectTypeModel model)
 {
     model.CopyTo(entity);
 }