public ActionResult CreatePartnerReport([FromBody] PartnerReportModel partnerReport) { _logger.LogInformation("Adding a new partner report"); partnerReport.CreatedOn = DateTime.Now; var partnerReportData = PartnerReportMapper.SerializePartnerReport(partnerReport); var newPartnerReport = _partnerReportService.CreateReport(partnerReportData); return(Ok(newPartnerReport)); }
public static PartnerReport SerializePartnerReport(PartnerReportModel partner) { return(new PartnerReport { Id = partner.Id, CaretakerUsernameId = partner.CaretakerUsernameId, CreatedOn = partner.CreatedOn, Progress = partner.Progress, Description = partner.Description, Problem = partner.Problem, Solution = partner.Solution, Document = partner.Document }); }
public IHttpActionResult Get() { // Validate the Header and return the token string token = ValidateHeader.validate(Request); if (token == null) { return(BadRequest(HttpErrorMessages.InvalidHeader)); } // Validate the Token and return 'BadRequest' or 'Unauthorized' if it's the case int typeOfAuth = 1; HttpStatusCode Status = TokenValidation.validatetoken(token, typeOfAuth); IHttpActionResult response = ResponseMessage(new HttpResponseMessage(Status)); // If the Token is Valid, execute service if (Status == HttpStatusCode.OK) { int eventID = TokenFactory.getEventIdPayload(token); try { DataClasses3DataContext dbContext = new DataClasses3DataContext(); var eventPartners = from u in dbContext.TbPartners where u.EventId == eventID && u.IsStaff == true // Staff only orderby u.PartnerLabel ascending select new { PartnerID = u.PartnerId, PartnerLabel = u.PartnerLabel }; var eventProfiles = from u in dbContext.TbProfiles where u.EventId == eventID && u.Staff == true // Staff only orderby u.ProfileLabel ascending select new { ProfileID = u.ProfileId, ProfileLabel = u.ProfileLabel }; ReportingFilterLists reportingFilterLists = new ReportingFilterLists(); List <PartnerReportModel> partnerList = new List <PartnerReportModel>(); // Default entry PartnerReportModel partnerReportModelDefault = new PartnerReportModel(); partnerReportModelDefault.partnerID = -1; partnerReportModelDefault.partnerLabel = "todos"; partnerList.Add(partnerReportModelDefault); foreach (var item1 in eventPartners) { PartnerReportModel partnerReportModel = new PartnerReportModel(); partnerReportModel.partnerID = item1.PartnerID; partnerReportModel.partnerLabel = item1.PartnerLabel; partnerList.Add(partnerReportModel); } List <ProfileReportModel> profileList = new List <ProfileReportModel>(); // Default entry ProfileReportModel profileReportModelDefault = new ProfileReportModel(); profileReportModelDefault.profileID = -1; profileReportModelDefault.profileLabel = "todos"; profileList.Add(profileReportModelDefault); foreach (var item2 in eventProfiles) { ProfileReportModel profileReportModel = new ProfileReportModel(); profileReportModel.profileID = item2.ProfileID; profileReportModel.profileLabel = item2.ProfileLabel; profileList.Add(profileReportModel); } reportingFilterLists.partnerList = partnerList; reportingFilterLists.profileList = profileList; return(Ok(reportingFilterLists)); } catch (Exception e) { return(InternalServerError(e)); } } else { return(response); } }