Ejemplo n.º 1
0
 public ResultViewModel<FacultyViewModel> Create([FromBody] FacultyViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Faculty faculty = new Faculty();
             faculty.Name = model.Name;
             var res = _applicationDbContext.Faculties.Add(faculty);
             var result = _applicationDbContext.SaveChanges();
             return new ResultViewModel<FacultyViewModel>(new FacultyViewModel(faculty));
         }
         return new ResultViewModel<FacultyViewModel>("Model is not valid");
     }
     catch (Exception e)
     {
         return new ResultViewModel<FacultyViewModel>(e.ToString());
     }
 }
Ejemplo n.º 2
0
 public FacultyViewModel(Faculty fac)
 {
     this.Name = fac.Name;
     this.Id = fac.Id;
 }