Esempio n. 1
0
        public async Task <IActionResult> Delete(string id)
        {
            var query = new Loader <VisibleFile> {
                Id = id
            };
            await DataHandler.Execute(query);

            if (query.Result != null && AuthoriseWrite(query.Result))
            {
                var delete = new FileDelete {
                    CloudHandler = CloudHandler, File = query.Result
                };
                await LogicHandler.Execute(delete);

                if (delete.Result.Success)
                {
                    await DataHandler.Commit();

                    return(Ok(ConfirmViewModel.CreateSuccess(id)));
                }

                return(Ok(ConfirmViewModel.CreateFailure("Failed to delete file")));
            }

            return(Unauthorized());
        }
Esempio n. 2
0
        public override async Task <IActionResult> Post([FromBody] MeetingViewModel viewModel)
        {
            var model = await Parse(viewModel);

            if (AuthoriseWrite(model))
            {
                model.Participants = viewModel.Attendees.Select(f => f.Id).ToList();

                var attendCheck = new AttendCheck()
                {
                    CurrentUser  = CurrentUser,
                    DataHandler  = DataHandler,
                    LogicHandler = LogicHandler,
                    Meeting      = model
                };
                await LogicHandler.Execute(attendCheck);

                if (attendCheck.Result)
                {
                    await DataHandler.Commit();

                    return(Ok(ConfirmViewModel.CreateSuccess(attendCheck.Meeting)));
                }
                else
                {
                    return(Ok(ConfirmViewModel.CreateFailure("Failed to save Meeting")));
                }
            }

            return(Unauthorized());
        }
Esempio n. 3
0
        public override async Task <IActionResult> Delete(string id)
        {
            var loader = new Loader <Tenant>()
            {
                Id = CurrentUser.TenantId
            };
            await DataHandler.Execute(loader);

            if (loader.Result == null)
            {
                return(NotFound());
            }

            if (AuthoriseWrite(loader.Result))
            {
                var delete = new TenantDelete()
                {
                    Id = id
                };
                await DataHandler.Execute(delete);

                if (delete.Result)
                {
                    await DataHandler.Commit();

                    return(Ok(ConfirmViewModel.CreateSuccess(id)));
                }

                return(Ok(ConfirmViewModel.CreateFailure("Failed to delete")));
            }

            return(Unauthorized());
        }
Esempio n. 4
0
        protected async Task <ConfirmViewModel> Save(T model)
        {
            if (AuthoriseWrite(model))
            {
                var persist = new Persist <T> {
                    Model = model
                };
                await DataHandler.Execute(persist);

                return(ConfirmViewModel.CreateSuccess(persist.Model));
            }

            return(ConfirmViewModel.CreateFailure("Failed Authorisation on " + model.GetType().Name));
        }
Esempio n. 5
0
        public async Task <IActionResult> Recur([FromBody] RecurViewModel viewModel)
        {
            var loader = new Loader <Meeting>()
            {
                Id = viewModel.MeetingId
            };
            await DataHandler.Execute(loader);

            if (loader.Result == null)
            {
                return(NotFound());
            }

            if (loader.Result.AuthorId == CurrentUser.Id ||
                (loader.Result.TenantId == CurrentUser.TenantId &&
                 (CurrentUser.Right.CanAdmin || CurrentUser.Right.CanAuth)) || CurrentUser.Right.CanSuperuser)
            {
                var model = new Meeting()
                {
                    Participants  = loader.Result.Participants,
                    AuthorId      = CurrentUser.Id,
                    AuthorName    = CurrentUser.Name,
                    TenantId      = CurrentUser.TenantId,
                    TenantName    = CurrentUser.TenantName,
                    MeetingTypeId = loader.Result.MeetingTypeId,
                    RegionKey     = CurrentUser.RegionKey,
                    Text          = loader.Result.Text,
                    Name          = loader.Result.Name,
                    IsPrivate     = loader.Result.IsPrivate,
                    When          = viewModel.When,
                    PreviousId    = loader.Result.Id,
                    ForceNotify   = false
                };

                var attendCheck = new AttendCheck()
                {
                    CurrentUser  = CurrentUser,
                    DataHandler  = DataHandler,
                    LogicHandler = LogicHandler,
                    Meeting      = model
                };

                await LogicHandler.Execute(attendCheck);

                if (attendCheck.Result)
                {
                    loader.Result.NextId     = attendCheck.Meeting.Id;
                    loader.Result.IsComplete = true;

                    var persist = new Persist <Meeting> {
                        Model = loader.Result
                    };
                    await DataHandler.Execute(persist);

                    if (persist.Confirm.Success)
                    {
                        await DataHandler.Commit();

                        return(Ok(ConfirmViewModel.CreateSuccess(attendCheck.Meeting)));
                    }
                }

                return(Ok(ConfirmViewModel.CreateFailure("Failed to save Meeting")));
            }

            return(Unauthorized());
        }