Beispiel #1
0
        public ActionResult SavePost(string Title, string ShortDes, string LongDes, bool IsShow, string Tags,
            int Price, int? Discount, bool IsExist, string ProductUnit, ICollection<Domain.ViewModel.Mutual.FileUpload> files)
        {
            if (IsValidSessions())
            {

                //TempData["result"] = "OK";
                Tabs Tab = (Tabs)TempData["Tabs"];
                int value1 = Tab.GroupId;
                string TabName = Tab.TabName;
                int ServiceTabId = Tab.TabId;
                ServiceTab ServiceTab = new ServiceTab();

                ServiceTab.Name = TabName;
                ServiceTab.ServiceGroupId = Convert.ToInt32(value1);
                ServiceTab.TabType = 1;
                ServiceTab.IsShow = IsShow;
                ServiceTab.Title = Title;
                ServiceTab.ProductUnit = ProductUnit;
                ServiceTab.ShortText = ShortDes;
                ServiceTab.TabTypeText = LongDes;
                ServiceTab.Price = Price;
                ServiceTab.IsExist = IsExist;

                if (Discount.HasValue)
                {
                    ServiceTab.Discount = Discount;
                    if (Price < Discount.Value)
                    {
                        TempData["Message"] = "امکان ثبت تخفیف بیش از قیمت وجود ندارد.";
                        return Json(false);
                    }
                }
                else
                {
                    ServiceTab.Discount = 0;
                }

                ServiceTab.Tags = Tags;
                ServiceTab.CreationDate = DateTime.Now.Date;
                _RService.SaveServiceTab(ServiceTab);

                //Update all its serviceGroup  grandsonCount of its ancestors
                if (TabName == "شرح محصول" || TabName == "Product Description")
                {
                    UpdateGrandSonNumbers(ServiceTab.ServiceGroupId, true);
                }

                //update hasTab of parent servicegroup
                var parentNode = _RService.ServiceGroups.FirstOrDefault(_ => _.Id == Tab.GroupId);
                parentNode.HasTab = true;
                _RService.SaveServiceGroup(parentNode);

                TempData["FolderId"] = ServiceTab.Id;
                if (files != null)
                {
                    foreach (var img in files)
                    {
                        if (System.IO.File.Exists(Server.MapPath($"~/Upload/{img.fileName}")))
                        {
                            MoveTemporaryImage(img, ServiceTab.Id);
                        }
                    }
                }

                TempData.Keep("FolderId");
                TempData["result"] = "OK";
                TempData["Message"] = "عملیات با موفقیت انجام شد.";

                return Json(new { Idms = ServiceTab.Id }, JsonRequestBehavior.AllowGet);
            }

            return RedirectToAction("Login", "Home");
        }
Beispiel #2
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");
        }
Beispiel #3
0
 public void DeleteServiceTab(ServiceTab ServiceTab)
 {
     _RServiceTab.Remove(ServiceTab);
     _uow.SaveChanges();
 }
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 SaveServiceTab(ServiceTab ServiceTab)
 {
     if (ServiceTab.Id == 0)
     {
       _RServiceTab.Add(ServiceTab);
     }
     else
     {
         _uow.Entry(ServiceTab).State = EntityState.Modified;
     }
     _uow.SaveChanges();
 }