Esempio n. 1
0
 private ExerciseTypeDTO MapExerciseType(ExerciseType model)
 {
     var modelDTO = new ExerciseTypeDTO
     {
         Id = model.Id,
         Name = model.Name,
         IsFavorite = model.IsFavorite,
         ApplicationUser = model.ApplicationUser
     };
     return modelDTO;
 }
Esempio n. 2
0
 public void Create(ExerciseType entity)
 {
     repository.Create(entity);
 }
Esempio n. 3
0
 public void Update(ExerciseType entity)
 {
     repository.Update(entity);
 }
Esempio n. 4
0
 public async Task<JsonResult> Create(CreateExerciseTypeViewModel viewModel)
 {
     var user = await userManager.FindByIdAsync(User.Identity.GetUserId());
     if (user == null)
     {
         return Json(HttpStatusCode.Unauthorized.ToString());
     }
     if (ModelState.IsValid)
     {
         var exercise = new ExerciseType
         {
             Name = viewModel.Name
         };
         var oldExercise = exerciseTypeService.Find(e =>
             e.ApplicationUser.Id == user.Id &&
             e.Name == exercise.Name).ToList();
         if (oldExercise.Count == 0)
         {
             exercise.ApplicationUser = user;
             exerciseTypeService.Create(exercise);
             return Json("Created successfully");
         }
         else
         {
             return Json("An exercise with such name already exists");
         }
     }
     string errors = "";
     foreach (var modelState in ModelState.Values)
     {
         foreach (var error in modelState.Errors)
         {
             errors += error.ErrorMessage + ". ";
         }
     }
     // error
     return Json(errors);
 }