예제 #1
0
        public ActionResult Edit(int? id, string Title, string Description, string Url, int WorkType, int UserId, String DateSubmitted, bool PartcipateInPoll, bool ApprovedForPoll, bool Live, bool Featured, int PollId, HttpPostedFileBase[] Photos)
        {
            WorkBl work = new WorkBl();
            int _id = id != null ? int.Parse(id.ToString()) : 0;
            Work _work = work.Save(_id, Title, Description, Url, (WorkType)WorkType, UserId, DateTime.Parse(DateSubmitted), PartcipateInPoll, ApprovedForPoll, Live, Featured, PollId);

            if (Photos != null)
            {
                foreach (HttpPostedFileBase file in Photos)
                {
                    if(file != null)
                    {
                        string ogFilePath = System.IO.Path.Combine(Server.MapPath(ImageFiles.SaveFilePath(Work.FolderPath)));
                        file.SaveAs(ogFilePath);

                        string filePath = ImageFiles.Resize(1000, 1000, ogFilePath, Work.FolderPath);
                        string previewPath = ImageFiles.Resize(813, 500, ogFilePath, Work.FolderPath);
                        string thumbPath = ImageFiles.Crop(216, 150, ogFilePath, Work.FolderPath);
                        string iconPath = ImageFiles.Crop(50, 50, ogFilePath, Work.FolderPath);                    
                    
                        PhotoBl photo = new PhotoBl();
                        photo.Save(0, _work.Id, PhotoType.Work, filePath, previewPath, thumbPath, iconPath);

                        //delete og file path when done in case its too big
                        System.IO.File.Delete(ogFilePath);
                    }                   

                }
            }

            return RedirectToAction("edit", "work", new { id = _work.Id });
        }
        public ActionResult Edit(int? id, string Title, string Description, string Url, int _WorkType, bool Live, HttpPostedFileBase[] BrowsePhotos)
        {
            if (ModelState.IsValid)
            {
                WorkBl work = new WorkBl();
                int _id = id != null ? int.Parse(id.ToString()) : 0;

                //get currentwork
                if (_id > 0)
                {
                    Work thisWork = work.GetById(_id);
                    if (thisWork.User.Id != Assets.CurrentUser.Id)
                    {
                        TempData["Error"] = string.Format("Operation failed");
                        return RedirectToAction("index");
                    }
                }

                if(string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(Description) ||
                    string.IsNullOrWhiteSpace(Title) || string.IsNullOrWhiteSpace(Description)
                    )
                {
                    TempData["Error"] = string.Format("Operation failed");
                    return RedirectToAction("index");
                }

                if (_WorkType == (int)WorkType.Websites && (string.IsNullOrEmpty(Url) || string.IsNullOrWhiteSpace(Url)))
                {
                    TempData["Error"] = string.Format("Please add a url for this type of a project");
                    return RedirectToAction("index");
                }
                //save
                Work _work = work.Save(_id, Title, Description, Url, (WorkType)_WorkType, Assets.CurrentUser.Id, DateTime.Now, true, false, Live, false, 1);

                if (BrowsePhotos != null)
                {
                    foreach (HttpPostedFileBase file in BrowsePhotos)
                    {
                        if (file != null)
                        {
                            try
                            { 
                                string ogFilePath = System.IO.Path.Combine(Server.MapPath(ImageFiles.SaveFilePath(Work.FolderPath)));
                                file.SaveAs(ogFilePath);

                                string filePath = ImageFiles.Resize(1000, 1000, ogFilePath, Work.FolderPath);
                                string previewPath = ImageFiles.Resize(813, 500, ogFilePath, Work.FolderPath);
                                string thumbPath = ImageFiles.Crop(216, 150, ogFilePath, Work.FolderPath);
                                string iconPath = ImageFiles.Crop(50, 50, ogFilePath, Work.FolderPath);
                            
                                PhotoBl photo = new PhotoBl();
                                photo.Save(0, _work.Id, PhotoType.Work, filePath, previewPath, thumbPath, iconPath);

                                //delete og file path when done in case its too big
                                System.IO.File.Delete(ogFilePath);
                            }
                            catch
                            {
                                work.Delete(_work.Id);
                                TempData["Error"] = string.Format("An error occured while processing your images. Make sure your images are in the correct format");
                                return RedirectToAction("index");
                            }
                        }

                    }
                }
                TempData["Success"] = string.Format("{0}, successfully saved", _work.Title);
            }
            return RedirectToAction("index");
        }