public ResultSvc <InstructorCamp> AddInstructorToCamp(int instructorId, int campBatchId, int instructorRoleId) { var result = new ResultSvc <InstructorCamp>(new InstructorCamp { CampBatchId = campBatchId, InstructorId = instructorId, InstructorRoleId = instructorRoleId }); try { var campBatch = CampBatches.Items.Include(x => x.InstructorCamps).FirstOrDefault(x => x.Id == campBatchId); if (!campBatch.InstructorCamps.Any(x => x.InstructorId == instructorId && x.InstructorRoleId == instructorRoleId)) { campBatch.InstructorCamps.Add(new InstructorCamp { InstructorId = instructorId, InstructorRoleId = instructorRoleId }); campBatch.UserUpdatedId = Context.HttpContext.User.GetUserId(); CampBatches.Update(campBatch); } else { result.Errors.Add("Tábor již obsahuje tohoto instruktora ve zvolené roli!"); } } catch (Exception e) { Logger.LogError(e.Message); } return(result); }
public ResultSvc <CampBatch> CreateCampBatch(CampBatch campBatch) { var result = new ResultSvc <CampBatch>(campBatch); try { if (!CampBatches.Items.Any(x => x.Batch == campBatch.Batch && x.CampId == campBatch.CampId && x.From == campBatch.From && x.To == campBatch.To)) { campBatch.UserCreatedId = Context.HttpContext.User.GetUserId(); CampBatches.Add(campBatch); } else { result.Errors.Add("Tento turnus ve stejném datu již existuje!"); } } catch (Exception e) { Logger.LogError(e.Message); } return(result); }