Exemplo n.º 1
0
        public async Task <ResponseModel> Item(int id)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                TrainingType md = await _context.TrainingTypeRepository.FirstOrDefaultAsync(m => m.Id == id);

                TrainingTypeModel model = new TrainingTypeModel()
                {
                    Id          = md.Id,
                    Name        = md.Name,
                    Description = md.Description,
                    Precedence  = md.Precedence,
                    IsActive    = md.IsActive,
                    RowVersion  = md.RowVersion,
                };

                response.Result = model;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(response);
        }
Exemplo n.º 2
0
        public async Task <ResponseModel> Delete(TrainingTypeModel model)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                TrainingType md = await _context.TrainingTypeRepository.FirstOrDefaultAsync(m => m.Id == model.Id);

                if (!md.RowVersion.SequenceEqual(model.RowVersion))
                {
                    response.ResponseStatus = Core.CommonModel.Enums.ResponseStatus.OutOfDateData;
                    return(response);
                }

                md.Deleted    = true;
                md.UpdateBy   = base.UserId;
                md.UpdateDate = DateTime.Now;

                _context.TrainingTypeRepository.Update(md);

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(response);
        }
Exemplo n.º 3
0
        public async Task <ResponseModel> Insert(TrainingTypeModel model)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                TrainingType md = new TrainingType();

                md.Name        = model.Name;
                md.Description = model.Description;
                md.Precedence  = model.Precedence;
                md.IsActive    = model.IsActive;
                md.CreateBy    = base.UserId;
                md.CreateDate  = DateTime.Now;

                await _context.TrainingTypeRepository.AddAsync(md).ConfigureAwait(true);

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(response);
        }
Exemplo n.º 4
0
        private static TrainingTypeModel PrepareTrainingTypeModel(TrainingType trainingType)
        {
            TrainingTypeModel trainingTypeTemp = new TrainingTypeModel();

            trainingTypeTemp.Id   = trainingType.Id;
            trainingTypeTemp.Name = trainingType.Name;
            if (trainingType.IsActive != null)
            {
                trainingTypeTemp.IsActive = trainingType.IsActive.Value;
            }
            return(trainingTypeTemp);
        }
Exemplo n.º 5
0
        public async Task <ResponseModel> Delete([FromBody] TrainingTypeModel model)
        {
            var response = await _trainingTypeService.Delete(model);

            return(response);
        }
Exemplo n.º 6
0
 protected TrainingViewModel(TrainingTypeModel type)
 {
     Type = type;
 }