Exemplo n.º 1
0
        public async Task <IActionResult> GetPlaces()
        {
            var result = await _executor
                         .Add <GetPlacesOperation>()
                         .Map <PlaceToPlaceModelMapping>()
                         .Execute();

            return(result.CreateHttpResult());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get()
        {
            var temp   = User.Claims.ToList();
            var result = await _executor
                         .Add <GetTasksOperation>()
                         .Map <AppTaskToAppTaskModelMapping, List <AppTask> >(last => last)
                         .Execute();

            return(result.CreateHttpResult());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UploadPicture(List <IFormFile> files, [FromRoute] PictureType pictureType, [FromQuery] Guid?accountId)
        {
            // Get form file in two ways. First for how the app transmits it, second for the webapp.
            var file = files.SingleOrDefault();

            if (file == null)
            {
                file = Request.Form.Files.SingleOrDefault();
            }
            if (file == null)
            {
                return(BadRequest("Invalid Form"));
            }

            _executor
            .Add <UploadPictureOperation, (IFormFile, string)>(() => (file, pictureType.ToString().ToLower()))
            .Add <AddPictureOperation, (Guid id, string link), (Guid, PictureType, string)>(r => (r.id, pictureType, r.link));

            if (pictureType == PictureType.Gallery)
            {
                Picture picture = null;
                _executor
                .Add <AnalyzePictureOperation, Picture, Picture>(p => p)
                .Add <CreatePictureActivityOperation, Picture, (Guid, ActivityType)>(p =>
                {
                    picture = p;
                    return(p.Id, ActivityType.PictureAdded);
                })
                .Add <AddActivityOperation, PictureActivity, AddActivityOperation.Request>(a => new AddActivityOperation.Request(
                                                                                               new ActivityMetadataModel
                {
                    ActiveStepId = null,
                    ActiveTaskId = null,
                    Latitude     = null,
                    Longitude    = null,
                    Timestamp    = DateTimeOffset.UtcNow
                },
                                                                                               a))
                .Map <PictureToPictureModelMapping>(() => picture);
            }
            else
            {
                if (pictureType == PictureType.Profile)
                {
                    _executor.Add <SetProfilePictureOperation, Picture, (Picture, Guid)>(last => (last, accountId.Value));
                }

                _executor.Map <PictureToPictureModelMapping, Picture>(last => last);
            }

            var result = await _executor.Execute();

            return(result.CreateHttpResult());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetMobileAppSettings()
        {
            var result = await _executor
                         .Add <GetMobileAppSettingsOperation>()
                         .Execute();

            return(result.CreateHttpResult());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetReportActivites()
        {
            var result = await _executor
                         .Add <GetReportActivitiesOperation>()
                         .Map <ReportActivitiesToDictionaryMapping, IEnumerable <ReportActivity> >(a => a)
                         .Execute();

            return(result.CreateHttpResult());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetTemplates()
        {
            var result = await _executor
                         .Add <GetDayTemplatesOperation, Guid>(() => User.GetTenantId().Value)
                         .Map <DayTemplateModelToDayTemplateMapping, List <DayTemplate> >(t => t)
                         .Execute();

            return(result.CreateHttpResult());
        }
        public async Task <IActionResult> LogGeneralActivtiy(GeneralApiActivityType?activityType, [FromBody] GeneralActivityModel metadata)
        {
            var activityData = metadata.ActivityData?.ToDictionary(kvp => kvp.Key, kvp => (object)kvp.Value);

            var result = await _executor
                         .Add <CreateGeneralActivityOperation, ActivityType>(() => (ActivityType)activityType.Value)
                         .Add <AddActivityOperation, GeneralActivity, AddActivityOperation.Request>(a => new AddActivityOperation.Request(metadata, a, activityData))
                         .Execute();

            // Return empty payload if succeeded
            return(result.ResultType == OperationResultType.Succeeded ? Ok() : result.CreateHttpResult());
        }
Exemplo n.º 8
0
        public async Task <IActionResult> UpsertDay([FromBody] UpsertedDayModel day, [FromQuery] bool steamrollerMode)
        {
            _executor
            .Validate(ModelState)
            .Map <UpsertedDayModelToUpsertedDayMapping>(() => day)
            .Add <ValidateIsUtcStartOfDayOperation, UpsertedDay, (DateTimeOffset, object)>(d => (d.Date, d));

            if (!steamrollerMode)
            {
                _executor
                .Add <ValidateScheduledTasksOperation, UpsertedDay, ScheduledTasksValidationModel>(d => new ScheduledTasksValidationModel(d, d.Tasks, d.Date));
            }

            var result = await _executor
                         .Add <UpsertDayOperation, UpsertedDay, (Guid, UpsertedDay)>(d => (User.GetTenantId().Value, d))
                         .Execute();

            return(result.CreateHttpResult());
        }
Exemplo n.º 9
0
        public async Task <IActionResult> UpdateTaskFeedback(Guid taskId, [FromBody] UpdateTaskFeedbackModel model)
        {
            var operationsModel = new UpdateTaskFeedbackOperationsModel
            {
                TaskId          = taskId,
                NewTaskFeedback = model.Feedback
            };

            var result = await _executor
                         .Add <UpdateTaskFeedbackOperation, UpdateTaskFeedbackOperationsModel>(() => operationsModel)
                         .Add <CreateScheduledTaskActivityOperation, (Guid taskId, ActivityType type)>(() => (taskId, ActivityType.TaskFeedback))
                         .Add <AddActivityOperation, ScheduledTaskActivity, AddActivityOperation.Request>(activity =>
                                                                                                          new AddActivityOperation.Request(model, activity, new Dictionary <string, object>
            {
                [ScheduledTaskActivity.FeedbackDataKey] = model.Feedback
            }))
                         .Execute();

            // Return empty payload if succeeded
            return(result.ResultType == OperationResultType.Succeeded ? Ok() : result.CreateHttpResult());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> UpdateStepState(Guid stepId, [FromBody] UpdateStepStateModel model)
        {
            var operationsModel = new UpdateStepStateOperationsModel
            {
                NewStepState = model.State,
                StepId       = stepId
            };

            var result = await _executor
                         .Add <ValidateStepStateChangeOperation, UpdateStepStateOperationsModel>(() => operationsModel)
                         .Add <UpdateStepStateOperation, UpdateStepStateOperationsModel, UpdateStepStateOperationsModel>(m => m)
                         .Add <CreateScheduledStepActivityOperation, (Guid taskId, ActivityType type)>(() => (stepId, ActivityType.StepState))
                         .Add <AddActivityOperation, ScheduledStepActivity, AddActivityOperation.Request>(activity =>
                                                                                                          new AddActivityOperation.Request(model, activity, new Dictionary <string, object>
            {
                [ScheduledStepActivity.StateDataKey] = model.State
            }))
                         .Execute();

            // Return empty payload if succeeded
            return(result.ResultType == OperationResultType.Succeeded ? Ok() : result.CreateHttpResult());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> GetDay()
        {
            var otpContext = OtpContext.FromPrincipal(User);

            IOperationResult result = null;

            if (otpContext.TryParse <DayOtpModel>(out var model))
            {
                Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = model.Culture.ToCultureInfo();

                result = await _executor
                         .Add <GetDaysOperation, GetDaysOperation.Input>(() => new GetDaysOperation.Input(model.Date, model.Date, User.GetTenantId()))
                         .Add <ParseTemplateOperation, List <Day>, ParseTemplateOperation.Input>(days => new ParseTemplateOperation.Input
                {
                    Model       = days.FirstOrDefault(),
                    TemplateKey = "Day"
                })
                         .Add <HtmlToPdfOperation, ParseTemplateOperation.Output, HtmlToPdfOperation.Input>(last => new HtmlToPdfOperation.Input(last.Result))
                         .Execute();
            }

            if (result?.ResultType == OperationResultType.Succeeded)
            {
                return(new FileContentResult(result.GetResult <HtmlToPdfOperation.Output>().Pdf, "application/pdf"));
            }
            else
            {
                string htmlResult;
                if (_hostingEnvironment.IsDevelopment())
                {
                    htmlResult = result.Error?.ToString();
                }
                else
                {
                    htmlResult = "Error";
                }
                return(new OkObjectResult(htmlResult));
            }
        }