コード例 #1
0
        public IActionResult ValidateCode([FromBody] PaperMill model)
        {
            if (model == null)
            {
                return(NotFound());
            }
            if (General.IsDevelopment)
            {
                logger.LogDebug(ModelState.ToJson());
            }
            var existing = repository.Get().FirstOrDefault(a => a.PaperMillCode == model.PaperMillCode);

            if (existing == null)
            {
                return(Accepted(true));
            }
            if (existing.PaperMillId != model.PaperMillId)
            {
                return(UnprocessableEntity(Constants.ErrorMessages.EntityExists("Code")));
            }
            else
            {
                return(Accepted(true));
            }
        }
コード例 #2
0
        private bool validateEntity(PaperMill model)
        {
            var validCode = repository.ValidateCode(model);

            if (!validCode)
            {
                ModelState.AddModelError(nameof(PaperMill.PaperMillCode), Constants.ErrorMessages.EntityExists("Code"));
            }
            return(ModelState.ErrorCount == 0);
        }
コード例 #3
0
        public bool ValidateCode(PaperMill model)
        {
            var existing = Get().FirstOrDefault(a => a.PaperMillCode == model.PaperMillCode);

            if (existing == null)
            {
                return(true);
            }
            return(existing.PaperMillId == model.PaperMillId);
        }
コード例 #4
0
 public IActionResult Get([FromQuery] PaperMill parameters = null)
 {
     try
     {
         var model = repository.Get(parameters);
         return(Ok(model));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.FetchError));
     }
 }
コード例 #5
0
        public PaperMill Update(PaperMill model)
        {
            var entity = dbContext.PaperMills.Find(model.PaperMillId);

            if (entity == null)
            {
                throw new Exception("Selected Record does not exists.");
            }

            entity.PaperMillCode = (model.PaperMillCode ?? "").ToUpper();
            entity.IsActive      = model.IsActive;

            dbContext.PaperMills.Update(entity);
            dbContext.SaveChanges();
            return(entity);
        }
コード例 #6
0
 public IActionResult Post([FromBody] PaperMill model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(InvalidModelStateResult());
         }
         if (!validateEntity(model))
         {
             return(InvalidModelStateResult());
         }
         return(Accepted(repository.Create(model)));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
     }
 }
コード例 #7
0
 public IActionResult Put([FromBody] PaperMill model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(InvalidModelStateResult());
         }
         if (!validateEntity(model))
         {
             return(InvalidModelStateResult());
         }
         if (repository.Get().Count(a => a.PaperMillId.Equals(model.PaperMillId)) == 0)
         {
             return(NotFound(Constants.ErrorMessages.NotFoundEntity));
         }
         return(Accepted(repository.Update(model)));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.UpdateError));
     }
 }
コード例 #8
0
 public SqlRawParameter GetSqlRawParameter(PaperMill parameters)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public bool ValidateName(PaperMill model) => throw new NotImplementedException();
コード例 #10
0
 public IQueryable <PaperMill> Get(PaperMill parameters = null)
 {
     return(dbContext.PaperMills.AsNoTracking());
 }
コード例 #11
0
 public bool Delete(PaperMill model)
 {
     dbContext.PaperMills.Remove(model);
     dbContext.SaveChanges();
     return(true);
 }
コード例 #12
0
 public PaperMill Create(PaperMill model)
 {
     dbContext.PaperMills.Add(model);
     dbContext.SaveChanges();
     return(model);
 }