Beispiel #1
0
        public ActionResult AddFlash(HttpPostedFileBase FlashFile)
        {
            if (IsValidSessions())
            {
                Tabs Tabs = (Tabs)TempData["Tabs"];
                int value1 = Tabs.GroupId;
                string TabName = Tabs.TabName;
                int ServiceTabId = Tabs.TabId;
                // TempData["Tabs"] = Tabs;
                bool isValid1 = false;
                string filename1 = "";
                if (FlashFile != null)
                {
                    if (FlashFile.ContentLength > 0)
                    {
                        filename1 = SaveFlash(FlashFile, null);
                        if (filename1 != "")
                        {
                            if (_RService.DetailsServiceTab(ServiceTabId) == null)
                            {
                                ServiceTab ServiceTab = new ServiceTab()
                                {
                                    CreationDate = DateTime.Now.Date,
                                    Name = TabName,
                                    ServiceGroupId = Convert.ToInt32(value1),
                                    TabType = 3

                                };
                                _RService.SaveServiceTab(ServiceTab);
                                ServiceTabId = ServiceTab.Id;
                                Tabs.TabId = ServiceTab.Id;
                            }
                            isValid1 = true;
                            TempData["result"] = "OK";
                            TempData["Message"] = "عملیات با موفقیت ثبت شد.";
                        }
                        else
                        {
                            TempData["result"] = "Error";
                            TempData["Message"] = "فایل ارسالی مجاز نمی باشد";
                            return View();
                        }
                    }

                    if (isValid1)
                    {
                        ServiceTabFile ServiceTabFile = new ServiceTabFile();
                        ServiceTabFile.File = filename1;
                        ServiceTabFile.ServiceTabId = ServiceTabId;
                        _RService.SaveServiceTabFile(ServiceTabFile);
                        ViewBag.FileName = filename1;
                        TempData["result"] = "OK";
                        TempData["Message"] = "عملیات با موفقیت ثبت شد.";
                    }
                }
                //  TempData["Tabs"] = Tabs;
                return RedirectToAction("ProductList");
            }
            else
                return RedirectToAction("Login", "Home");
        }
        // Begin of core PUT/POST execution method, values can be edited, or request can be aborted
        async Task handler_StoreFileRequestStartedAsync(object sender, Eventing.Args.StoreFileRequestEventArgs e)
        {
            string ExtFile = "";
            int FolderId = 0;
            if (TempData["FolderId"] != null)
            {
                FolderId = Convert.ToInt32(TempData["FolderId"]);
                TempData["FolderId"] = FolderId;
            }

            if (e.Param.FileStatusItem.StorageInfo.FilePath != 
                Server.MapPath("~/Files/ServiceGallery/" + FolderId + "/") + e.Param.FileStatusItem.FileName)
            {
                ExtFile = "ErrorPath";
            }
            // GetFileExtension Ext = new GetFileExtension();
            var extt = Path.GetExtension(e.Param.FileStatusItem.FileName);
            if (extt != ".jpg" && extt != ".png" && extt != ".jpeg" && extt != ".gif")
            {
                ExtFile = "ErrorExt";
            }

            if (ExtFile != "" && ExtFile == "ErrorPath")
            {
                e.Param.FileStatusItem.ErrorMessage = "مسیر فایل اشتباه است .";
                e.Param.FileStatusItem.Success = false;
            }
            if (ExtFile != "" && ExtFile == "ErrorExt")
            {
                e.Param.FileStatusItem.ErrorMessage = "نوع فایل معتبر نیست .";
                e.Param.FileStatusItem.Success = false;

            }
            if (ExtFile == "")
            {
                EFDbContext EFDbContext = new EFDbContext();
                string Filen = e.Param.FileStatusItem.FileName;

                int find = Filen.LastIndexOf(".");
                // var ext = Filen.Substring(find, Filen.Length - find);
                var MainName = Filen.Substring(0, find);
                MainName = ChangeUnKnownCharacters(MainName);
                e.Param.FileStatusItem.FileName = DateTime.Now.Ticks + MainName + extt;
                e.Param.FileStatusItem.UpdateStatus(true);

                ServiceTabFile Item = new ServiceTabFile();
                Item.File = e.Param.FileStatusItem.FileName;
                Item.ServiceTabId = FolderId;
                EFDbContext.ServiceTabFiles.Add(Item);
                EFDbContext.SaveChanges();

            }
            e.Context.PipelineControl.Message.MessageText += string.Format(_logpattern, "log-post", "StoreFileRequestStartedAsync", DateTime.Now.ToLongTimeString());
        }
Beispiel #3
0
        private bool MoveTemporaryImage(Domain.ViewModel.Mutual.FileUpload image, int productId)
        {
            var extension = Path.GetExtension(image.fileName);
            var newName = DateTime.Now.Ticks.ToString() + extension;

            var path = $"/Files/ServiceGallery/{productId}";
            var serverPath = Server.MapPath($"~/Files/ServiceGallery/{productId}");

            if (!Directory.Exists(serverPath))
            {
                Directory.CreateDirectory(serverPath);
            }

            System.IO.File.Move(Server.MapPath($"~/Upload/{image.fileName}"), serverPath + "/" + newName);

            var dBRecord = new ServiceTabFile()
            {
                File = newName,
                Alt = image.title,
                Description = image.description,
                ServiceTabId = productId
            };

            return _RService.SaveServiceTabFile(dBRecord);
        }
Beispiel #4
0
        public ActionResult UploadFiles(SelectedFileModel elem)
        {
            if (IsValidSessions())
            {
                var fileName = elem.fileName;

                GetFileExtension Ext = new GetFileExtension();
                if (Ext.GetExtension(fileName) == "jpg" ||
                    Ext.GetExtension(fileName) == "png" ||
                    Ext.GetExtension(fileName) == "jpeg" ||
                    Ext.GetExtension(fileName) == "png")
                {
                    Tabs Tab = (Tabs)TempData["Tabs"];

                    int value1 = Tab.GroupId;
                    string TabName = Tab.TabName;
                    int ServiceTabId = Tab.TabId;

                    if (_RService.DetailsServiceTab(ServiceTabId) == null)
                    {
                        ServiceTab ServiceTab = new ServiceTab()
                        {
                            CreationDate = DateTime.Now.Date,
                            Name = TabName,
                            ServiceGroupId = Convert.ToInt32(value1),
                            TabType = 2

                        };
                        _RService.SaveServiceTab(ServiceTab);
                        ServiceTabId = ServiceTab.Id;
                        Tab.TabId = ServiceTab.Id;
                    }
                    TempData["Tabs"] = Tab;

                    var fileContent = elem.fileContent;
                    var category = elem.category;
                    var title = elem.title;
                    var base64String = fileContent.Split(',')[1];
                    fileName = DateTime.Now.Ticks + "_" + category + "_" + title + "_" +
                        CommonMethods.ChangeUnKnownCharacters(Path.GetFileNameWithoutExtension(fileName))
                        + "." + Ext.GetExtension(fileName);
                    ServiceTabFile ServiceTabFile = new ServiceTabFile
                    {
                        File = fileName,
                        ServiceTabId = ServiceTabId
                    };
                    _RService.SaveServiceTabFile(ServiceTabFile);
                    var filePath = Server.MapPath("~/Images/TabGalleryService/") + fileName;
                    var bytes = Convert.FromBase64String(base64String);

                    System.IO.File.WriteAllBytes(filePath, bytes);

                    ImageResizer.ImageBuilder.Current.Build(Server.MapPath("~/Images/TabGalleryService/")
                        + fileName,
                        Server.MapPath("~/Images/TabGalleryService/thum/") + fileName,
                        new ImageResizer.ResizeSettings(200, 200, ImageResizer.FitMode.Crop, ""));

                    #region Comments
                    //ImageResizer.ImageBuilder.Current.Build(Server.MapPath("~/Images/TabGalleryService/") + fileName,
                    //    Server.MapPath("~/Images/TabGalleryService/") + fileName,
                    //    new ImageResizer.ResizeSettings(400, 400, ImageResizer.FitMode.Stretch, ""));

                    //System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath("~/Images/TabGalleryService/" + fileName));
                    //System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = (ThumbnailCallback);
                    //int height = fullSizeImg.Height;
                    //int width = fullSizeImg.Width;
                    //if (height > width)
                    //{
                    //    height = (height * 200) / width;
                    //    width = 200;
                    //}
                    //else
                    //{
                    //    width = (width * 200) / height;
                    //    height = 200;
                    //}
                    //System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(width, height, dummyCallBack, IntPtr.Zero);
                    //thumbNailImg.Save(Server.MapPath("~/Images/TabGalleryService/thum/") + fileName);

                    //ImageResizer.ImageBuilder.Current.Build(Server.MapPath("~/Images/TabGalleryService/thum/") + fileName, Server.MapPath("~/Images/TabGalleryService/thum/") + fileName, new ImageResizer.ResizeSettings(200, 200, ImageResizer.FitMode.Crop, ""));
                    //thumbNailImg.Dispose();
                    //fullSizeImg.Dispose();
                    #endregion

                    TempData["result"] = "OK";
                    TempData["Message"] = "عملیات با موفقیت ثبت شد.";
                    return Json(fileName, JsonRequestBehavior.AllowGet);
                }
                return Json("error", JsonRequestBehavior.AllowGet);
            }

            return RedirectToAction("Login", "Home");
        }
Beispiel #5
0
 public void DeleteImageGallery(ServiceTabFile ServiceTabFile)
 {
     System.IO.File.Delete(HttpContext.Current.Server.MapPath("~/Images/TabGalleryService/" + ServiceTabFile.File));
     System.IO.File.Delete(HttpContext.Current.Server.MapPath("~/Images/TabGalleryService/thum/" + ServiceTabFile.File));
     _RService.DeleteServiceTabFile(ServiceTabFile);
 }
Beispiel #6
0
 public void DeleteServiceTabFile(ServiceTabFile ServiceTabFile)
 {
     _RServiceTabFile.Remove(ServiceTabFile);
     _uow.SaveChanges();
 }
Beispiel #7
0
        public bool SaveServiceTabFile(ServiceTabFile ServiceTabFile)
        {
            if (ServiceTabFile.Id == 0)
            {
                _RServiceTabFile.Add(ServiceTabFile);
            }
            else
            {
                _uow.Entry(ServiceTabFile).State = EntityState.Modified;
            }
            var result = _uow.SaveChanges() > 0;

            return result;
        }