public ScheduleModel CreateViewModel(Schedule datamodel) { if (datamodel == null) { throw new ArgumentNullException("datamodel"); } var result = new ScheduleModel() { Id = datamodel.Id, Name = datamodel.Name, UserId = datamodel.UserID, Url = _UrlHelper.Link("GetScheduleById", new { id = datamodel.Id }) }; if (datamodel.Exercises != null && datamodel.Exercises.Any()) { result.Exercises = datamodel.Exercises.Select(x => new EntryModel <int>() { Id = x.Id, Name = x.Name, Url = _UrlHelper.Link("GetExerciseById", new { id = x.Id }), }); } return(result); }
public Schedule CreateModel(ScheduleModel model, Schedule datamodel = null) { var result = datamodel ?? new Schedule(); result.UserID = model.UserId; result.Name = model.Name; result.Id = model.Id; return(result); }