public IActionResult Post([FromBody] Speciality speciality)
        {
            if (speciality.Id == null)
            {
                _dbContext.Specialities.Add(speciality);

                _dbContext.SaveChanges();

                return(new ObjectResult(speciality));
            }
            else
            {
                var existingSpeciality = _dbContext.Specialities.FirstOrDefault(x => x.Id == speciality.Id);

                existingSpeciality.Name = speciality.Name;

                _dbContext.SaveChanges();

                return(new ObjectResult(existingSpeciality));
            }
        }
Esempio n. 2
0
        public IActionResult Post([FromBody] Group group)
        {
            if (group.Id == null)
            {
                _dbContext.Groups.Add(group);

                _dbContext.SaveChanges();

                return(new ObjectResult(group));
            }
            else
            {
                var existingGroup = _dbContext.Groups.FirstOrDefault(x => x.Id == group.Id);

                existingGroup.Name         = group.Name;
                existingGroup.SpecialityId = group.SpecialityId;
                existingGroup.Course       = group.Course;
                existingGroup.Quantity     = group.Quantity;

                _dbContext.SaveChanges();
                return(new ObjectResult(existingGroup));
            }
        }