public IActionResult CreateLink(IoTDTO iot, [FromServices] IFormManager formManager, [FromServices] IIdeationManager ideationManager, [FromServices] IIoTManager ioTManager, [FromServices] UnitOfWorkManager unitOfWorkManager) { IotLink link = null; Location location = new Location() { Longitude = iot.Location.Longitude, Latitude = iot.Location.Latitude, ZoomLevel = iot.Location.ZoomLevel }; if (iot.IsForm) { Form form = formManager.GetForm(iot.FormId); if (form == null) { return(NotFound()); } link = ioTManager.CreateIotLink(form, null, form.Project, location); } else { Ideation ideation = ideationManager.GetIdeationWithReplies(iot.IdeationId); IdeationReply reply = ideationManager.GetIdeationReply(ideation.Replies[0].IdeationReplyId); if (reply == null) { return(NotFound()); } link = ioTManager.CreateIotLink(null, reply, ideation.Project, location); } unitOfWorkManager.Save(); return(Created("", new { id = link.IotLinkId })); }
public IActionResult GetAllAdminIdeations(int id, [FromServices] IIoTManager ioTManager) { List <Ideation> ideations = _ideationManager.GetAllAdminIdeations(id).ToList(); List <IdeationViewModel> ideationViewModels = new List <IdeationViewModel>(); foreach (var ideation in ideations) { bool hasReplies = ideation.Replies.Any(); if (!hasReplies) { continue; } IoTDTO iotLink = null; if (hasReplies) { IotLink link = null; link = ioTManager.GetIoTLinkByIdeationReply(ideation.Replies[0]); if (link != null) { iotLink = new IoTDTO() { IotLinkId = link.IotLinkId, IsForm = false, IdeationId = ideation.Replies[0].IdeationReplyId, Location = new LocationDTO() { Longitude = link.Location.Longitude, Latitude = link.Location.Latitude, ZoomLevel = link.Location.ZoomLevel } }; } } IdeationViewModel vm = new IdeationViewModel() { CentralQuestion = ideation.CentralQuestion, Description = ideation.Description, IdeationId = ideation.IdeationId, HasReplies = hasReplies, IotLink = iotLink }; ideationViewModels.Add(vm); } return(Ok(ideationViewModels)); }
public IActionResult EditLink(IoTDTO iot, [FromServices] IFormManager formManager, [FromServices] IIdeationManager ideationManager, [FromServices] IIoTManager ioTManager, [FromServices] UnitOfWorkManager unitOfWorkManager) { IotLink link = ioTManager.GetIoTLink(iot.IotLinkId); Location location = new Location() { Longitude = iot.Location.Longitude, Latitude = iot.Location.Latitude, ZoomLevel = iot.Location.ZoomLevel }; link.Location = location; ioTManager.UpdateIotLink(link); unitOfWorkManager.Save(); return(Ok()); }
public IActionResult GetIoTLinksByPlatform(int platformId, [FromServices] IIoTManager ioTManager) { List <IotLink> iotLinks = ioTManager.GetIotLinksByPlatform(platformId).ToList(); List <IoTDTO> iots = new List <IoTDTO>(); foreach (var iotLink in iotLinks) { IoTDTO ioT = new IoTDTO() { Location = new LocationDTO() { Latitude = iotLink.Location.Latitude, Longitude = iotLink.Location.Longitude, ZoomLevel = iotLink.Location.ZoomLevel }, IsForm = iotLink.Form != null, }; if (iotLink.Form != null) { ioT.Question = iotLink.Form.Questions[0].QuestionString; int upvotes = iotLink.Form.Replies.Select(f => ((SingleChoiceAnswer)f.Answers[0]).SelectedChoice).Count(c => c == 1); int downvotes = iotLink.Form.Replies.Select(f => ((SingleChoiceAnswer)f.Answers[0]).SelectedChoice).Count(c => c == 0); ioT.UpVotes = upvotes; ioT.DownVotes = downvotes; ioT.FormId = iotLink.Form.FormId; } else { ioT.Question = iotLink.IdeationReply.Ideation.CentralQuestion; ioT.UpVotes = iotLink.IdeationReply.Upvotes; ioT.DownVotes = iotLink.IdeationReply.Downvotes; ioT.IdeationId = iotLink.IdeationReply.IdeationReplyId; } iots.Add(ioT); } return(Ok(iots)); }