Exemplo n.º 1
0
        public ActionResult Share(FormCollection form)
        {
            var fileselected = form.GetValues("Select");
            List<Int64> listoffiles = new List<Int64>();
            ShareDocuments model = new ShareDocuments();

            if (fileselected != null && fileselected.ToList().Count>0)
            {
                fileselected.ToList();
                foreach (var file in fileselected)
                    listoffiles.Add(Convert.ToInt64(file));
                var shareFiles = from filetable in db.DX_FILES where listoffiles.Contains(filetable.fileid) && filetable.ownerid == SessionKeyMgmt.UserId select filetable;

                if (shareFiles != null && shareFiles.ToList().Count > 0)
                {
                    foreach (DX_FILES file in shareFiles)
                    {
                        if (file.islocked != true)
                        {
                            model.Files = shareFiles.ToList();
                            SessionKeyMgmt.SharedFiles = model.Files;
                        }
                        else
                        {
                            ModelState.AddModelError("", "One or more file is checked out please check-In so as to do sharing");
                            return RedirectToAction("ListDocuments");
                        }
                    }
                }
                if(listoffiles.Count > shareFiles.ToList().Count)
                {
                    ModelState.AddModelError("","Some files got deleted before you shared the documents");
                    return RedirectToAction("ListDocuments");
                }
            }
            else
            {
                ModelState.AddModelError("", "No Files Selected!");
                return RedirectToAction("ListDocuments");
            }
            model.shareWithUsers = new List<string>();
            populateUsersList();
            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult ShareFiles(ShareDocuments files)
        {
            if (files != null && files.shareWithUsers != null)
            {
                files.Files = SessionKeyMgmt.SharedFiles;

                try
                {
                    List<Int64> fileIdList = new List<Int64>();
                    foreach (DX_FILES file in files.Files)
                    {
                        fileIdList.Add(Convert.ToInt64(file.fileid));
                    }
                    foreach (string user in files.shareWithUsers)
                    {
                        foreach (Int64 fileId in fileIdList)
                        {
                            var listofsharedfiles = from privilegetable in db.DX_PRIVILEGE where privilegetable.fileid == fileId && privilegetable.userid == user select privilegetable;

                            if (listofsharedfiles.ToList().Count > 0)
                            {
                                foreach (DX_PRIVILEGE existingfile in listofsharedfiles)
                                {
                                    if (existingfile.reason != "inherit" && existingfile.reason != "owner")
                                    {
                                        existingfile.read = true;
                                        existingfile.delete = false;
                                        existingfile.update = files.update;
                                        existingfile.check = files.check;
                                    }
                                }
                            }
                            else
                            {
                                DX_PRIVILEGE sharedfile = new DX_PRIVILEGE();
                                sharedfile.fileid = fileId;
                                sharedfile.userid = user;
                                sharedfile.read = true;
                                sharedfile.delete = false;
                                sharedfile.update = files.update;
                                sharedfile.check = files.check;
                                sharedfile.reason = "shared";
                                db.DX_PRIVILEGE.AddObject(sharedfile);
                            }
                        }
                    }
                    db.SaveChanges();
                }
                catch
                {
                    ModelState.AddModelError("", "Some Error occured. Try again after sometime!");
                }
                SessionKeyMgmt.SharedFiles = new List<DX_FILES>();
            }
            else
            {
                ModelState.AddModelError("", "Please select users!!");
            }
            return RedirectToAction("ListDocuments");
        }