예제 #1
0
        protected override void HandleOnNavigatedTo(NavigationEventArgs e)
        {
            base.HandleOnNavigatedTo(e);
            DocumentEditingViewModel viewModel = new DocumentEditingViewModel(long.Parse(((Page)this).NavigationContext.QueryString["OwnerId"]), long.Parse(((Page)this).NavigationContext.QueryString["Id"]), ((Page)this).NavigationContext.QueryString["Title"].ForUI());

            base.DataContext = viewModel;
            ApplicationBarIconButton applicationBarIconButton1 = new ApplicationBarIconButton();
            Uri uri1 = new Uri("/Resources/check.png", UriKind.Relative);

            applicationBarIconButton1.IconUri = uri1;
            string appBarMenuSave = CommonResources.AppBarMenu_Save;

            applicationBarIconButton1.Text = appBarMenuSave;
            ApplicationBarIconButton appBarButtonSave          = applicationBarIconButton1;
            ApplicationBarIconButton applicationBarIconButton2 = new ApplicationBarIconButton();
            Uri uri2 = new Uri("/Resources/appbar.cancel.rest.png", UriKind.Relative);

            applicationBarIconButton2.IconUri = uri2;
            string appBarCancel = CommonResources.AppBar_Cancel;

            applicationBarIconButton2.Text = appBarCancel;
            ApplicationBarIconButton applicationBarIconButton3 = applicationBarIconButton2;

            appBarButtonSave.Click += ((EventHandler)((p, f) =>
            {
                ((Control)this).Focus();
                viewModel.SaveChanges();
            }));
            applicationBarIconButton3.Click += ((EventHandler)((p, f) => Navigator.Current.GoBack()));
            this.ApplicationBar              = ((IApplicationBar)ApplicationBarBuilder.Build(new Color?(), new Color?(), 0.9));
            viewModel.PropertyChanged       += (PropertyChangedEventHandler)((p, f) => appBarButtonSave.IsEnabled = viewModel.IsFormCompleted);
            this.ApplicationBar.Buttons.Add(appBarButtonSave);
            this.ApplicationBar.Buttons.Add(applicationBarIconButton3);
        }
예제 #2
0
        public async Task <IActionResult> Create(int onBehalfOfUserId = -1)
        {
            var model = new DocumentEditingViewModel();

            ViewData["Title"]  = "Create document";
            ViewData["Action"] = "Create";
            if (onBehalfOfUserId != -1)
            {
                var user = await userService.GetUserSummary(onBehalfOfUserId);

                if (user == null)
                {
                    return(NotFound());
                }
                ViewData["OnBehalfUser"] = user;
                model.OnBehalfOfUserId   = user.Id;
            }
            return(View("Edit", model));
        }
예제 #3
0
        public async Task <IActionResult> CreateEdit(DocumentEditingViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", model));
            }

            var currentUserId = await authService.GetUserIdByClaims(User);

            var contents = mapper.Map <DocumentContentsDto>(model);


            if (model.Id != 0)
            {
                var success = await documentService.EditDocument(contents, model.Id, currentUserId);

                if (!success)
                {
                    ModelState.AddModelError(string.Empty, "Unable to edit the document");
                    return(View("Edit", model));
                }
                return(RedirectToAction("Details", "Document", new { model.Id }));
            }
            else
            {
                int id;
                if (model.OnBehalfOfUserId.HasValue)
                {
                    id = await documentService.CreateDocument(contents, model.OnBehalfOfUserId.Value, currentUserId);
                }
                else
                {
                    id = await documentService.CreateDocument(contents, currentUserId);
                }
                return(RedirectToAction("Details", "Document", new { id }));
            }
        }