예제 #1
0
        public IActionResult CreateExamCriterea(int id, [FromBody] List <ExamCritereaDto> examCriterea)
        {
            try
            {
                foreach (ExamCritereaDto item in examCriterea)
                {
                    ExamCriterea temp = _mapper.Map <ExamCriterea>(item);
                    temp.ExamID = id;

                    if (item.GeneralCritereaID == null)
                    {
                        GeneralCriterea tempcriterea = new GeneralCriterea();
                        tempcriterea.Name    = temp.Name;
                        tempcriterea.Advices = temp.Advices;

                        tempcriterea           = _generalCritereaService.Create(tempcriterea);
                        temp.GeneralCritereaID = tempcriterea.ID;
                    }

                    _examCritereaService.Create(temp);
                }

                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #2
0
        public void Delete(int id)
        {
            GeneralCriterea x = _context.GeneralCritereas.Find(id);

            if (x != null)
            {
                _context.GeneralCritereas.Remove(x);
                _context.SaveChanges();
            }
        }
예제 #3
0
        public GeneralCriterea Create(GeneralCriterea newObject)
        {
            if (_context.GeneralCritereas.Any(x => x.Name == newObject.Name))
            {
                throw new AppException("GeneralCriterea Name " + newObject.Name + " is already taken");
            }

            _context.GeneralCritereas.Add(newObject);
            _context.SaveChanges();

            return(_context.GeneralCritereas.First(x => x.Name == newObject.Name));
        }
        public IActionResult Create([FromBody] GeneralCritereaDto generalCritereaDto)
        {
            // map dto to entity and set id
            GeneralCriterea c = _mapper.Map <GeneralCriterea>(generalCritereaDto);

            try
            {
                // save
                c = _generalCritereaService.Create(c);
                return(Ok(_mapper.Map <GeneralCritereaDto>(c)));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(ex.Message));
            }
        }
예제 #5
0
        public GeneralCriterea Update(GeneralCriterea updatedObject)
        {
            GeneralCriterea x = _context.GeneralCritereas.Find(updatedObject.ID);

            if (x == null)
            {
                throw new AppException("GeneralCriterea not found");
            }

            /*copy properties here*/
            x.Name = updatedObject.Name;

            _context.GeneralCritereas.Update(x);
            _context.SaveChanges();

            return(x);
        }