public ActionResult Create(FolderForm folderForm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add insert logic here

                    var user = this.userManager.GetUserAsync(HttpContext.User).Result;

                    Folder folder = new Folder
                    {
                        Id        = ObjectId.GenerateNewId(),
                        Name      = folderForm.Name,
                        Messages  = new List <ObjectId>(),
                        Principal = false
                    };
                    user.Folders.Add(folder.Id);

                    this.mongoContext.Folders.InsertOne(folder);

                    UpdateDefinition <ApplicationUser> updateDefinition = Builders <ApplicationUser> .Update.Set(a => a.Folders, user.Folders);

                    this.mongoContext.ApplicationUsers.FindOneAndUpdate(a => a.NormalizedEmail.Equals(user.NormalizedEmail), updateDefinition);

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
        public ActionResult Edit(string id, FolderForm folderForm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add update logic here

                    var user = this.userManager.GetUserAsync(HttpContext.User).Result;

                    ObjectId objectId = new ObjectId(id);

                    if (!user.Folders.Contains(objectId))
                    {
                        TempData["ErrorMessage"] = "usted no puede modificar esta carpeta.";
                        return(RedirectToAction(nameof(Index)));
                    }

                    UpdateDefinition <Folder> updateDefinition = Builders <Folder> .Update.Set("Name", folderForm.Name);

                    this.mongoContext.Folders.FindOneAndUpdate(f => f.Id.Equals(objectId), updateDefinition);

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View(folderForm));
                }
            }
            return(View(folderForm));
        }
        public ActionResult Edit(string id)
        {
            var user = this.userManager.GetUserAsync(HttpContext.User).Result;

            ObjectId objectId = new ObjectId(id);

            var folder = this.mongoContext.Folders.Find(f => f.Id.Equals(objectId)).First();

            if (folder.Principal == true)
            {
                TempData["ErrorMessage"] = "Este carpeta no se puede modificar.";
                return(RedirectToAction(nameof(Index)));
            }
            else if (!user.Folders.Contains(objectId))
            {
                TempData["ErrorMessage"] = "usted no puede modificar esta carpeta.";
                return(RedirectToAction(nameof(Index)));
            }

            FolderForm folderForm = new FolderForm
            {
                Name = folder.Name
            };

            return(View(folderForm));
        }
        private void btnFolder_Click(object sender, EventArgs e)
        {
            Patient obj = patientBindingSource.Current as Patient;

            if (obj != null)
            {
                using (FolderForm frm = new FolderForm(obj.Id))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        MessageBox.Show("Cancel", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Register a path which will be saved as the state of this provider.
        /// </summary>
        /// <param name="savedState"></param>
        /// <param name="silent"></param>
        /// <returns></returns>
        public Task <string> Register(string savedState = null, bool silent = false)
        {
            var result = new TaskCompletionSource <string>();

            // Check if the saved path (state) is still exists - if it is, use it
            if (savedState != null && Directory.Exists(savedState))
            {
                state = savedState;

                result.SetResult(savedState);
                return(result.Task);
            }

            // If the saved state was not usable and silent is true, return with failure
            if (silent)
            {
                result.SetResult(null);
                return(result.Task);
            }

            // Get a new path with FolderForm
            var form    = new FolderForm();
            var success = false;

            form.OnResult += path =>
            {
                success = true;
                state   = path;

                result.SetResult(path);
                form.Close();
            };

            form.FormClosed += (sender, e) =>
            {
                if (success == false)
                {
                    result.SetResult(null);
                }
            };

            form.Show();

            return(result.Task);
        }