public (Guid Guid, Response Response) CreateReportCardDesign(NewReportDesignRequest request) { var validationResult = newReportCardDesignValidator.Validate(request); if (!validationResult.IsValid) { return(Guid.Empty, Response.CreateResponse(validationResult.Messages)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Guid.Empty, Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } var designs = reportDesignerQuery.GetReportCardDesigns(request.ClubId, request.Name); if (designs.Count() > 0) { return(Guid.Empty, Response.CreateResponse(new IllegalOperationException("There is already a report design with this name"))); } try { var design = new ReportCardDesign(request.ClubId) { DesignName = request.Name }; reportDesignerRepository.AddReportDesign(design); return(design.Guid.Value, Response.CreateSuccessResponse()); } catch (Exception ex) { return(Guid.Empty, Response.CreateResponse(ex)); } }
public void AddReportDesign(ReportCardDesign reportDesign) { string sql = @"INSERT INTO ReportCardDesigns(Guid, Name, ClubId) VALUES( @ReportCardDesignGuid, @Name, (SELECT ClubId FROM Clubs WHERE Guid = @ClubGuid))"; DynamicParameters p = new DynamicParameters(); p.Add("@ReportCardDesignGuid", reportDesign.Guid.ToString()); p.Add("@Name", reportDesign.DesignName); p.Add("@ClubGuid", reportDesign.ClubId.ToString()); using (var connection = connectionFactory.Connect()) { connection.Open(); connection.Execute(sql, p); } }