public ResultViewModel<SpecialtyViewModel> Create([FromBody] SpecialtyViewModel model) { try { if (ModelState.IsValid) { Specialty specialty = new Specialty(); specialty.Name = model.Name; specialty.FacultyId = model.FacultyId; var res = _applicationDbContext.Specialties.Add(specialty); var result = _applicationDbContext.SaveChanges(); return new ResultViewModel<SpecialtyViewModel>(new SpecialtyViewModel(specialty)); } return new ResultViewModel<SpecialtyViewModel>("Model is not valid"); } catch (Exception e) { return new ResultViewModel<SpecialtyViewModel>(e.ToString()); } }
public SpecialtyViewModel(Specialty spec) { this.Name = spec.Name; this.Id = spec.Id; this.FacultyId = spec.FacultyId; }