Пример #1
0
        public ActionResult Create(News news)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string new_image = Url.Content("/images/default-news-img.png");
                    for (int i = 0; i < Request.Form.Files.Count; i++)
                    {
                        var image = Request.Form.Files[i];
                        if (image != null && image.ContentType.Contains("image/"))
                        {
                            string fileName = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(image.FileName);

                            GoogleDriveManager driveClient = new GoogleDriveManager(hosting);

                            new_image = driveClient.DriveUploadAndGetSrc(image, DRIVE_FOLDER_NAME);
                        }
                    }
                    news.Images = new_image;

                    newsManager.AddNews(news);
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
Пример #2
0
        public ActionResult Edit(News news)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string new_image = Url.Content("/images/default-news-img.png");
                    // EDIT EXISTING IMAGE
                    string existingImages = managerForImages.FindNewsById(news.Id).Images;
                    if (!String.IsNullOrEmpty(existingImages))
                    {
                        string[] images = existingImages.Split('|');
                        foreach (string field in Request.Form.Keys)
                        {
                            if (field.Contains("check_"))
                            {
                                var    checkbox = Request.Form[field];
                                string src      = field.Split('_')[1];
                                if (checkbox == "false")
                                {
                                    GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                                    driveClient.DriveMoveFileToTrash(src);
                                }
                                else
                                {
                                    new_image = src;
                                }
                            }
                        }
                    }

                    // UPLOADING NEW IMAGE
                    for (int i = 0; i < Request.Form.Files.Count; i++)
                    {
                        var image = Request.Form.Files[i];
                        if (image != null && image.ContentType.Contains("image/"))
                        {
                            string fileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(image.FileName);

                            GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                            new_image = driveClient.DriveUploadAndGetSrc(image, DRIVE_FOLDER_NAME);
                        }
                    }
                    news.Images = new_image;

                    newsManager.EditNews(news);
                    return(Redirect("/News/Details/" + news.Id));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
Пример #3
0
        public ActionResult Edit(Partner pm)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Form.Files["downl"];
                if (file != null && file.ContentType.Contains("image/"))
                {
                    string fileName = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);

                    GoogleDriveManager driveClient = new GoogleDriveManager(hosting);

                    pm.Image = driveClient.DriveUploadAndGetSrc(file, DRIVE_FOLDER_NAME);
                }
                pmManager.Edit(pm);
                return(Redirect("/Partners"));
            }
            else
            {
                return(View());
            }
        }
Пример #4
0
        public ActionResult Edit(Service svc)
        {
            if (ModelState.IsValid)
            {
                string file_name = Request.Form["file_name"];
                string link      = Request.Form["link"];
                var    file      = Request.Form.Files["download"];
                if (file != null && file.Length > 0)
                {
                    GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                    link = driveClient.DriveUploadAndGetSrc(file, DRIVE_FOLDER_FILES);
                }
                svc.File = file_name + "|" + link;

                svcManager.EditService(svc);
                return(Redirect("/Services/Details/" + svc.Id));
            }
            else
            {
                return(View());
            }
        }
Пример #5
0
        public ActionResult Create(Models.Event e)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string new_image = Url.Content("/images/default-event-img.png");
                    var    image     = Request.Form.Files["Images"];
                    if (image != null && image.ContentType.Contains("image/"))
                    {
                        string             fileName    = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(image.FileName);
                        GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                        new_image = driveClient.DriveUploadAndGetSrc(image, DRIVE_FOLDER_IMAGES);
                    }
                    e.Images = new_image;

                    string file_name = Request.Form["file_name"];
                    string link      = Request.Form["link"];
                    var    file      = Request.Form.Files["download"];
                    if (file != null && file.Length > 0)
                    {
                        GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                        link = driveClient.DriveUploadAndGetSrc(file, DRIVE_FOLDER_FILES);
                    }
                    e.Files = file_name + "|" + link;

                    eventsManager.AddEvent(e);
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
Пример #6
0
        public ActionResult Edit(Models.Event e)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string new_image = Url.Content("/images/default-event-img.png");
                    // EDIT EXISTING IMAGES
                    string existingImages = managerForImages.FindEventById(e.Id).Images;
                    if (!String.IsNullOrEmpty(existingImages))
                    {
                        string[] images = existingImages.Split('|');
                        foreach (string field in Request.Form.Keys)
                        {
                            if (field.Contains("check_"))
                            {
                                var    checkbox = Request.Form[field];
                                string src      = field.Split('_')[1];
                                if (checkbox == "false" && !src.Contains("default"))
                                {
                                    GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                                    driveClient.DriveMoveFileToTrash(src);
                                }
                                else
                                {
                                    new_image = src;
                                }
                            }
                        }
                    }

                    // UPLOADING NEW IMAGES
                    for (int i = 0; i < Request.Form.Files.Count; i++)
                    {
                        var image = Request.Form.Files[i];
                        if (image != null && image.ContentType.Contains("image/"))
                        {
                            string fileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(image.FileName);

                            GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                            new_image = driveClient.DriveUploadAndGetSrc(image, DRIVE_FOLDER_IMAGES);
                        }
                    }
                    e.Images = new_image;

                    // Зарузка и формирование файла
                    string file_name = Request.Form["file_name"];
                    string link      = Request.Form["link"];
                    var    file      = Request.Form.Files["download"];
                    if (file != null && file.Length > 0)
                    {
                        GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                        link = driveClient.DriveUploadAndGetSrc(file, DRIVE_FOLDER_FILES);
                    }
                    e.Files = file_name + "|" + link;

                    eventsManager.EditEvent(e);
                    return(Redirect("/Events/Details/" + e.Id));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
Пример #7
0
        public ActionResult Settings(User account)
        {
            AccountManager manager = new AccountManager(database);
            string         exSep   = "|";
            string         inSep   = "^";

            string[] files = new string[3];

            // Загрузка логотипа

            var logoImage = Request.Form.Files["downl-logo"];

            if (logoImage != null && logoImage.Length > 0 && logoImage.ContentType.Contains("image"))
            {
                GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                account.Logo = driveClient.DriveUploadAndGetSrc(logoImage, DRIVE_FOLDER_NAME);
            }

            // Загрузка изображения в раздел "О нас"
            var aboutImage = Request.Form.Files["downl-about"];

            if (aboutImage != null && aboutImage.Length > 0 && aboutImage.ContentType.Contains("image"))
            {
                GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                account.AboutImage = driveClient.DriveUploadAndGetSrc(aboutImage, DRIVE_FOLDER_NAME);
            }

            // Телефоны
            List <string> phonesList = new List <string>();

            foreach (string field in Request.Form.Keys)
            {
                if (field.Contains("Phone"))
                {
                    phonesList.Add(Request.Form[field]);
                }
            }
            account.Phones = string.Join("|", phonesList);

            // Загрузка файлов на главной странице
            for (int i = 0; i < Request.Form.Files.Count - 2; i++)
            {
                string title = Request.Form["title" + i.ToString()];
                string link  = Request.Form["link" + i.ToString()];
                var    file  = Request.Form.Files["downl" + i];
                if (file != null && file.Length > 0)
                {
                    GoogleDriveManager driveClient = new GoogleDriveManager(hosting);
                    link = driveClient.DriveUploadAndGetSrc(file, DRIVE_FOLDER_NAME);
                }
                if (title != null && title.Length > 0 || link != null && link.Length > 0)
                {
                    files[i] = title + inSep + link;
                }
                else
                {
                    files[i] = "";
                }
            }
            account.Files = string.Join(exSep, files);

            account.Id = 1; /*стоит здесь, пока юзер в бд один*/
            if (account.Password == null || account.Password == string.Empty)
            {
                account.Password = Request.Form["oldPass"];
            }

            if (ModelState.IsValid)
            {
                manager.EditAccount(account);
            }
            return(Redirect("/Account/Settings"));
        }