Esempio n. 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));
            }
        }
Esempio n. 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);
        }
        public bool ValidateCode(PaperMill model)
        {
            var existing = Get().FirstOrDefault(a => a.PaperMillCode == model.PaperMillCode);

            if (existing == null)
            {
                return(true);
            }
            return(existing.PaperMillId == model.PaperMillId);
        }
Esempio n. 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));
     }
 }
        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);
        }
Esempio n. 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));
     }
 }
Esempio n. 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));
     }
 }
 public SqlRawParameter GetSqlRawParameter(PaperMill parameters)
 {
     throw new NotImplementedException();
 }
 public bool ValidateName(PaperMill model) => throw new NotImplementedException();
 public IQueryable <PaperMill> Get(PaperMill parameters = null)
 {
     return(dbContext.PaperMills.AsNoTracking());
 }
 public bool Delete(PaperMill model)
 {
     dbContext.PaperMills.Remove(model);
     dbContext.SaveChanges();
     return(true);
 }
 public PaperMill Create(PaperMill model)
 {
     dbContext.PaperMills.Add(model);
     dbContext.SaveChanges();
     return(model);
 }