Beispiel #1
0
        public async Task <ActionResult> DownLoadSelectedFile(int FileID, string UserIDOfPersonThatDownloadedTheFile)
        {
            File ObjFile = GetFileToDownload(FileID);

            string     errorMessage = "";
            AspNetUser FileOwner;
            AspNetUser PersonThatDownLoadedTheFile;

            FileOwner = db.AspNetUsers.Where(a => a.Id == ObjFile.UserIDOfFileOwner).FirstOrDefault();
            PersonThatDownLoadedTheFile = db.AspNetUsers.Where(a => a.Id == UserIDOfPersonThatDownloadedTheFile).FirstOrDefault();

            EmailSetting es = (from a in db.EmailSettings select a).FirstOrDefault <EmailSetting>();

            //Check To verify that the file has not been downloaded and locked
            //If it has been locked it means that it is iether being downloaded by the same user again or is a download from the file history.
            if ((from a in db.UserThatDownloadedFiles where a.FileID == FileID select a).Count() == 0)
            {
                ObjFile.FileLookupStatusID     = (int)Common.Enum.DBLookupEnum.FileViewStatus.FileIsLocked;
                ObjFile.UserThatDownloadedFile = new UserThatDownloadedFile
                {
                    FileID = FileID,
                    UserIDThatDownloadedFIle = UserIDOfPersonThatDownloadedTheFile,
                    DateDownloaded           = DateTime.Now
                };

                string ownerFullName = FileOwner.FirstName + " " + FileOwner.LastName;
                string PersonThatDownloadedTheFile_FullName = PersonThatDownLoadedTheFile.FirstName + "  " + PersonThatDownLoadedTheFile.LastName;
                //send message to the file owner informing the owner that the file has been down loaded by user.

                //await Common.Email.EmailHelper.sendMessageAsync(
                //               _ToAddress: FileOwner.Email,
                //               _FromAddress: FileOwner.Email,
                //               _FromName: ownerFullName,
                //               _ToName: ownerFullName,
                //               _Subject: "Over Docs System - File (" + ObjFile.FileID + " - " + ObjFile.FileName + "." + ObjFile.FileExtension + ") has been downloaded.",
                //               _Message: "Good day " + ownerFullName + ". <br/><br/>One of your files have been downloaded by :<br/>" + PersonThatDownloadedTheFile_FullName + " and been locked.< br />< br /> Regards Over Docs.",
                //                _Credentials_UserName: es.UserName,
                //                _Credentials_Password: es.Password,
                //                 _SMTP_HOST: es.SmtpHost,
                //                 _SMTP_PORT: es.SmtpPort,
                //                 _IsSsl: es.SslEnabled);

                //if the person that downloaded tehe file is a doofferent person to the owner send that person a message informing them that the file can be downloaded by them
                if (!(UserIDOfPersonThatDownloadedTheFile.Equals(FileOwner.Id)))
                {
                    //await Common.Email.EmailHelper.sendMessageAsync(
                    //              _ToAddress: PersonThatDownLoadedTheFile.Email,
                    //              _FromAddress: FileOwner.Email,
                    //              _FromName: ownerFullName,
                    //              _ToName: PersonThatDownloadedTheFile_FullName,
                    //              _Subject: "Over Docs System - File (" + ObjFile.FileID + " - " + ObjFile.FileName + "." + ObjFile.FileExtension + ") has been downloaded.",
                    //              _Message: "Good day " + PersonThatDownloadedTheFile_FullName + ". <br/><br/>You successfull downloadded the following File::<br/>(" + ObjFile.FileName + "." + ObjFile.FileExtension + ") and been locked for you, ONLY you may now edit the file.<br/>The file will remain locked for other users untill you upload it again!< br />< br /> Regards Over Docs.",
                    //               _Credentials_UserName: es.UserName,
                    //               _Credentials_Password: es.Password,
                    //                _SMTP_HOST: es.SmtpHost,
                    //                _SMTP_PORT: es.SmtpPort,
                    //                _IsSsl: es.SslEnabled);
                }
            }

            try
            {
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                throw;
            }

            if (ObjFile != null)
            {
                return(File(ObjFile.FileImage, ObjFile.ContentType, ObjFile.FileName + "." + ObjFile.FileExtension));
            }
            else
            {
                return(null);
            }
        }
        public async Task <ActionResult> AcceptFileRequest(int FileID, int NotificationID, string IDOfUserThatRequestedTheFileToBeShared, string IDOfTheFileOwner)
        {
            AspNetUser UserThatSentRequest; //IDOfUserThatRequestedTheFileToBeShared
            AspNetUser FileOwner;           //IDOfTheFileOwner (Person Currently Lofgged on)


            string GlobalErrorMessage = "";
            string rtnSuccessMessage  = "";

            Boolean UpdatedCorrectly = false;

            using (db)
            {
                try
                {
                    //updates the Notification acknolegemant to indicate that the notification has been responeded to.
                    Notification Noti = db.Notifications.Where(a => a.NotificationID == NotificationID).FirstOrDefault <Notification>();
                    if (!(Noti.UserHasAcknowledgement))
                    {
                        FileOwner = (from a in db.AspNetUsers
                                     where a.Id == IDOfTheFileOwner
                                     select a).FirstOrDefault <AspNetUser>();

                        UserThatSentRequest = (from a in db.AspNetUsers
                                               where a.Id == IDOfUserThatRequestedTheFileToBeShared
                                               select a).FirstOrDefault <AspNetUser>();

                        EmailSetting es = (from a in db.EmailSettings select a).FirstOrDefault <EmailSetting>();
                        var          PartialFileObject = db.Files.Where(a => a.FileID == FileID).Select(a => new { a.FileID, a.FileName, a.FileExtension }).FirstOrDefault();


                        //db.Files_U_SetFileStatus(FileID, (int)Common.Enum.DBLookupEnum.FileViewStatus.FileIsLocked);


                        FileSharedWithUser FSWU = new FileSharedWithUser()
                        {
                            UserIDOfSharedDocs = IDOfUserThatRequestedTheFileToBeShared,
                            FileID             = FileID,
                            DateShared         = DateTime.Now
                        };

                        Noti.UserHasAcknowledgement = true;

                        db.FileSharedWithUsers.Add(FSWU);

                        await db.SaveChangesAsync();

                        string FromName = FileOwner.FirstName + " " + FileOwner.LastName;
                        string ToName   = UserThatSentRequest.FirstName + " " + UserThatSentRequest.LastName;

                        //Email Message To the file owner. Notifying him/her of the that the Private File Was successfull shared  With the person that requested it.
                        //await Common.Email.EmailHelper.sendMessageAsync(
                        //   _ToAddress: FileOwner.Email,
                        //   _FromAddress: UserThatSentRequest.Email,
                        //   _FromName: FromName,
                        //   _ToName: ToName,
                        //   _Subject: "Over Docs System - File (" + PartialFileObject.FileID + " - " + PartialFileObject.FileName + "." + PartialFileObject.FileExtension + ") has been shared.",
                        //   _Message: "Good day " + FromName + ". <br/><br/>A file shared notifiction has been sent to you from the system to notify you that the following file has bee successfully Shared with " + ToName + " .<br/> File Name: " + PartialFileObject.FileName + "." + PartialFileObject.FileExtension + ".<br/>File Ref# " + FileID + ".<br/><br/> Regards Over Docs.",
                        //    _Credentials_UserName: es.UserName,
                        //    _Credentials_Password: es.Password,
                        //     _SMTP_HOST: es.SmtpHost,
                        //     _SMTP_PORT: es.SmtpPort,
                        //     _IsSsl: es.SslEnabled);

                        ////Email Message To the Person that requested the file. To Confirm that the file has been shared out with user and can now download if so desired.
                        //await Common.Email.EmailHelper.sendMessageAsync(
                        //   _ToAddress: UserThatSentRequest.Email,
                        //   _FromAddress: FileOwner.Email,
                        //   _FromName: ToName,
                        //   _ToName: FromName,
                        //   _Subject: "Over Docs System - Notification (" + PartialFileObject.FileID + " - " + PartialFileObject.FileName + "." + PartialFileObject.FileExtension + ") has been shared!",
                        //   _Message: "Good day " + ToName + ". <br/><br/>" + FromName + " has responded to your request to share the following file.<br/> (" + PartialFileObject.FileID + " - " + PartialFileObject.FileName + "." + PartialFileObject.FileExtension + ").<br/> The file has been successfully shared with you and is now viewable under you private documents.<br/>The file can now be download if you require it.<br/><br/> Regards Over Docs.",
                        //    _Credentials_UserName: es.UserName,
                        //    _Credentials_Password: es.Password,
                        //     _SMTP_HOST: es.SmtpHost,
                        //     _SMTP_PORT: es.SmtpPort,
                        //     _IsSsl: es.SslEnabled);

                        rtnSuccessMessage += "Notification has been successfully recorded and Email Notification Sent to the person that request it in forming them that the file is avaiable!";
                    }
                    else
                    {
                        rtnSuccessMessage += "Notification has been already successfully been sent both the owner and the person that request the file to be shared! please check you email.";
                    }
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors)
                    {
                        foreach (DbValidationError error in entityErr.ValidationErrors)
                        {
                            GlobalErrorMessage = "Error Property Name " + error.PropertyName + " : Error Message: " + error.ErrorMessage;
                        }
                    }
                }
                catch (Exception ex)
                {
                    GlobalErrorMessage = "Error : " + ex.Message.ToString();
                }


                return(Json(rtnSuccessMessage, JsonRequestBehavior.AllowGet));
            }
        }