public void SyncTasks(TaskSyncRequest syncReuest) { if (syncReuest == null) throw new ArgumentException("syncRequest can't be null", "syncReuest"); //todo: bad code here foreach and if :( var appType = (AppType)syncReuest.AppType; foreach (var taskItem in syncReuest.TaskItems) { if (taskItem.ActionType == (int)EntityActionType.Create) { var taskCommand = RMSMapper.Map<CrudTaskItem, CreateTaskCommand>(taskItem); taskCommand.AppType = appType; taskService.CreateTask(taskCommand); } if (taskItem.ActionType == (int)EntityActionType.Modify) { var taskCommand = RMSMapper.Map<CrudTaskItem, UpdateTaskCommand>(taskItem); taskCommand.AppType = appType; taskService.UpdateTask(taskCommand); } if (taskItem.ActionType == (int)EntityActionType.Delete) { var taskCommand = RMSMapper.Map<CrudTaskItem, DeleteTaskCommand>(taskItem); taskCommand.AppType = appType; taskService.DeleteTask(taskCommand); } } }
public IHttpActionResult PostTasks(TaskSyncRequest syncReuest) { taskService.SyncTasks(syncReuest); return Ok(); }