예제 #1
0
        public IActionResult InsertSlider()
        {
            Slider _slider  = JsonSerializer.Deserialize <Slider>(HttpContext.Request.Form["Slider"]);
            var    imageUrl = HttpContext.Request.Form.Files[0];

            FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(imageUrl, 1, "SliderImages");

            if (uploadFileStatus.Status == 200)
            {
                _slider.ImageUrl = uploadFileStatus.Path;
                _slider.CuserId  = userid;
                _slider.Cdate    = timeTick;
                _repository.Slider.Create(_slider);

                try
                {
                    _repository.Save();
                    _logger.LogInfo($"Insert Slider To database.");
                    return(Ok(""));
                }
                catch (Exception e)
                {
                    _logger.LogError($"Something went wrong inside InsertSlider Action: {e.Message}");
                    FileManeger.FileRemover(new List <string> {
                        uploadFileStatus.Path
                    });
                    return(BadRequest(e.Message.ToString()));
                }
            }
            else
            {
                _logger.LogError($"Something went wrong inside InsertSlider Action: {uploadFileStatus.Path}");
                return(BadRequest("Internal server error"));
            }
        }
        public IActionResult UploadPackingImage()
        {
            try
            {
                var tbl       = JsonSerializer.Deserialize <ProductPackingTypeImage>(HttpContext.Request.Form["ProductPackingTypeImage"]);
                var imageFile = HttpContext.Request.Form.Files.GetFile("PackingTypeImage");

                var _uploadFileStatus = FileManeger.FileUploader(imageFile, 1, "ProductPackingTypeImage");

                if (_uploadFileStatus.Status != 200)
                {
                    return(BadRequest(_uploadFileStatus.Path));
                }

                tbl.ImageFileUrl = _uploadFileStatus.Path;
                tbl.CuserId      = ClaimPrincipalFactory.GetUserId(User);
                tbl.Cdate        = DateTime.Now.Ticks;

                _repository.ProductPackingTypeImage.Create(tbl);
                _repository.Save();
                return(Ok(""));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(BadRequest(""));
            }
        }
        public IActionResult UploadPackingTypeImage()
        {
            try
            {
                var a = HttpContext.Request.Form.Files[0];

                FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(a, 1, "PackingTypeImages");
                var packingTypeImageDto = JsonSerializer.Deserialize <PackingTypeImageDto>(HttpContext.Request.Form["packingTypeImage"]);

                if (uploadFileStatus.Status == 200)
                {
                    var packingTypeImage = _mapper.Map <PackingTypeImage>(packingTypeImageDto);
                    packingTypeImage.Cdate        = DateTime.Now.Ticks;
                    packingTypeImage.CuserId      = ClaimPrincipalFactory.GetUserId(User);
                    packingTypeImage.ImageFileUrl = uploadFileStatus.Path;
                    _repository.PackingTypeImage.Create(packingTypeImage);
                    _repository.Save();
                    return(Created("", packingTypeImage));
                }
                else
                {
                    return(BadRequest(""));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Internal Server Error"));
            }
        }
        public IActionResult InsertProductImage(long productId, long colorId)
        {
            try
            {
                var productImageUrl = HttpContext.Request.Form.Files[0];
                FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(productImageUrl, 1, "ProductImages");
                if (uploadFileStatus.Status == 200)
                {
                    ProductImage productImage = new ProductImage
                    {
                        ImageUrl  = uploadFileStatus.Path,
                        ColorId   = colorId,
                        ProductId = productId,
                        //CuserId= userid
                        DaDate = timeTick
                    };

                    _repository.ProductImage.Create(productImage);
                    _repository.Save();
                    _logger.LogInfo($"Insert ProductImage To database.");
                    return(Ok(""));
                }
                else
                {
                    _logger.LogError($"Something went wrong inside InsertProductImage action: {uploadFileStatus.Path}");
                    return(BadRequest("Internal server error"));
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Something went wrong inside InsertProductImage action: {e.Message}");
                return(BadRequest("Internal server error"));
            }
        }
예제 #5
0
        public IActionResult InsertSlider()
        {
            var sliderdto = JsonSerializer.Deserialize <SliderDto>(HttpContext.Request.Form["Slider"]);
            var _slider   = _mapper.Map <Slider>(sliderdto);
            var imageUrl  = HttpContext.Request.Form.Files[0];

            var uploadFileStatus = FileManeger.FileUploader(imageUrl, 1, "SliderImages");

            if (uploadFileStatus.Status != 200)
            {
                return(BadRequest("Internal server error"));
            }

            _slider.ImageUrl = uploadFileStatus.Path;
            _slider.CuserId  = ClaimPrincipalFactory.GetUserId(User);
            _slider.Cdate    = DateTime.Now.Ticks;
            _repository.Slider.Create(_slider);



            try
            {
                _repository.Save();
                return(Created("", _slider));
            }
            catch (Exception e)
            {
                FileManeger.FileRemover(new List <string> {
                    uploadFileStatus.Path
                });
                return(BadRequest(e.Message.ToString()));
            }
        }
        public IActionResult UploadImage(long productId, int type, string title)
        {
            try
            {
                ProductImage tbl = new ProductImage();

                var a   = HttpContext.Request.Form.Files[0];
                var dir = "";
                dir = type == 1 ? "ProductImages" : "ProductVideo";

                var _uploadFileStatus = FileManeger.FileUploader(a, (short)type, dir);

                if (_uploadFileStatus.Status != 200)
                {
                    return(BadRequest(_uploadFileStatus.Path));
                }

                tbl.ProductId = productId;
                tbl.Title     = title;
                tbl.FileType  = type;
                tbl.ImageUrl  = _uploadFileStatus.Path;
                tbl.CuserId   = ClaimPrincipalFactory.GetUserId(User);
                tbl.Cdate     = DateTime.Now.Ticks;

                _repository.ProductImage.Create(tbl);
                _repository.Save();
                return(Ok(""));
            }
            catch (Exception e)
            {
                return(BadRequest(""));
            }
        }
예제 #7
0
        public IActionResult InsertProduct()
        {
            Product _product      = JsonSerializer.Deserialize <Product>(HttpContext.Request.Form["Product"]);
            var     coverImageUrl = HttpContext.Request.Form.Files[0];

            FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(coverImageUrl, 1, "ProductImages");

            Seller seller = new Seller();

            if (uploadFileStatus.Status == 200)
            {
                _product.CoverImageUrl = uploadFileStatus.Path;

                userid = User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).Select(x => x.Value).SingleOrDefault();
                if (_product.SellerId == null || _product.SellerId == 0)
                {
                    seller = _repository.Seller.FindByCondition(c => c.UserId == userid).FirstOrDefault();
                }
                else
                {
                    seller = _repository.Seller.FindByCondition(c => c.Id == _product.SellerId).FirstOrDefault();
                }

                _product.SellerId = seller.Id;

                var catProduct = _repository.CatProduct.FindByCondition(c => c.Id == _product.CatProductId)
                                 .FirstOrDefault();
                var counter = (_repository.Product
                               .FindByCondition(c => c.SellerId == seller.Id && c.CatProductId == catProduct.Id)
                               .Count() + 1).ToString();
                counter          = counter.PadLeft(3, '0');
                _product.Coding  = long.Parse(seller.SellerCode.ToString() + catProduct.Coding.ToString() + counter);
                _product.CuserId = userid;
                _product.Cdate   = timeTick;
                _repository.Product.Create(_product);

                try
                {
                    _repository.Save();
                    _logger.LogInfo($"Insert Product To database.");
                    return(Ok(""));
                }
                catch (Exception e)
                {
                    _logger.LogError($"Something went wrong inside Insert Product To database: {e.Message}");
                    FileManeger.FileRemover(new List <string> {
                        uploadFileStatus.Path
                    });
                    return(BadRequest(e.Message.ToString()));
                }
            }
            else
            {
                _logger.LogError($"Something went wrong Insert Product To database: {uploadFileStatus.Path}");
                return(BadRequest("Internal server error"));
            }
        }
예제 #8
0
 // File Funktions
 //----------------------------------------------------------------------------------------
 internal void AddFile(ProjectFile item)
 {
     if (_FileManager == null && !string.IsNullOrEmpty(ProjectPath))
     {
         _FileManager = new FileManeger(new ProjectFolder(ProjectPath));
         _FileManager.FileListHasChanged += OnFileListChanged;
     }
     _FileManager.Add(item);
 }
예제 #9
0
        public IActionResult InsertProduct()
        {
            Product _product      = JsonSerializer.Deserialize <Product>(HttpContext.Request.Form["Product"]);
            var     coverImageUrl = HttpContext.Request.Form.Files[0];

            FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(coverImageUrl, 1, "ProductImages");

            Seller seller = new Seller();

            if (uploadFileStatus.Status == 200)
            {
                _product.CoverImageUrl = uploadFileStatus.Path;

                var userid = ClaimPrincipalFactory.GetUserId(User);
                if (_product.SellerId == null || _product.SellerId == 0)
                {
                    seller = _repository.Seller.FindByCondition(c => c.UserId == userid).FirstOrDefault();
                }
                else
                {
                    seller = _repository.Seller.FindByCondition(c => c.Id == _product.SellerId).FirstOrDefault();
                }

                _product.SellerId = seller.Id;

                var catProduct = _repository.CatProduct.FindByCondition(c => c.Id == _product.CatProductId)
                                 .FirstOrDefault();
                var counter = (_repository.Product
                               .FindByCondition(c => c.SellerId == seller.Id && c.CatProductId == catProduct.Id)
                               .Count() + 1).ToString();
                counter          = counter.PadLeft(3, '0');
                _product.Coding  = long.Parse(seller.SellerCode.ToString() + catProduct.Coding.ToString() + counter);
                _product.CuserId = userid;
                _product.Cdate   = DateTime.Now.Ticks;
                _repository.Product.Create(_product);

                try
                {
                    _repository.Save();

                    return(Created("", _product));
                }
                catch (Exception e)
                {
                    FileManeger.FileRemover(new List <string> {
                        uploadFileStatus.Path
                    });
                    return(BadRequest(e.Message.ToString()));
                }
            }
            else
            {
                return(BadRequest("Internal server error"));
            }
        }
        private string GetProjectSavePath()
        {
            string filename = FileManeger.SaveProjectDialog(Properties.Settings.Default.DirProject, _Project.ProjectName);

            if (!string.IsNullOrEmpty(filename))
            {
                return(filename);
            }
            else
            {
                throw new Exception("Canceled");
            }
        }
예제 #11
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Form           form      = new Form();
            MessageService service   = new MessageService();
            FileManeger    maneger   = new FileManeger();
            FileManegerDB  manegerDB = new FileManegerDB();

            FormPresenter presenter = new FormPresenter(form, maneger, manegerDB, service);

            Application.Run(form);
        }
예제 #12
0
        public LongResult UploadSellerDocument(long documentId)
        {
            try
            {
                var userId = ClaimPrincipalFactory.GetUserId(User);
                var seller = _repository.Seller.FindByCondition(c => c.UserId == userId).FirstOrDefault();
                if (seller == null)
                {
                    return(LongResult.GetFailResult("فروشنده پیدا نشد!"));
                }


                var documentfile = HttpContext.Request.Form.Files.GetFile("Document");
                if (documentfile != null)
                {
                    var docpath          = "";
                    var uploadFileStatus = FileManeger.FileUploader(documentfile, 1, "SellerDocuments");
                    if (uploadFileStatus.Status == 200)
                    {
                        docpath = uploadFileStatus.Path;
                    }
                    else
                    {
                        return(LongResult.GetFailResult(uploadFileStatus.Path));
                    }

                    SellerDocument doc = new SellerDocument
                    {
                        FileUrl    = docpath,
                        SellerId   = seller.Id,
                        CuserId    = userId,
                        Cdate      = DateTime.Now.Ticks,
                        DocumentId = documentId
                    };
                    _repository.SellerDocument.Create(doc);
                    _repository.Save();

                    return(LongResult.GetSingleSuccessfulResult(doc.Id));
                }

                return(LongResult.GetFailResult("فایلی بارگزاری نشده است"));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(LongResult.GetFailResult(e.Message));
            }
        }
예제 #13
0
 private void tsmiAddXML_Click(object sender, EventArgs e)
 {
     if (IsActiveChildProjectOverview)
     {
         try
         {
             ProjectOverview overview;
             overview = (ProjectOverview)this.ActiveMdiChild;
             overview.AddFile(new ProjectFile(FileManeger.OpenFile(ProjectFile.Type.Xml), ProjectFile.Type.Xml));
         }
         catch (Exception ex)
         {
             MessageBox.Show("Can't Add the file");
             Log.Error(ex.Message);
         }
     }
 }
예제 #14
0
        // Serializing
        //----------------------------------------------------------------------------------------
        public Project(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new System.ArgumentNullException("info");
            }
            _ModuleManeger = (ModuleManeger)info.GetValue("ModuleManeger", typeof(ModuleManeger));
            _FileManager   = (FileManeger)info.GetValue("FileManeger", typeof(FileManeger));
            _ModuleManeger.TimesHasChanged   += OnTimesHasChanged;
            _ModuleManeger.ModulesHasChanged += OnProjectHasChanged;

            _ProjectName         = (string)info.GetValue("ProjectName", typeof(string));
            _ProjectCompletePath = (string)info.GetValue("ProjectPath", typeof(string));
            _projectDone         = (bool)info.GetValue("ProjectDone", typeof(bool));
            _Notes    = (string)info.GetValue("Notes", typeof(string));
            _Priority = (int)info.GetValue("Priority", typeof(int));
            _ID       = (int)info.GetValue("ID", typeof(int));
        }
예제 #15
0
        public IActionResult InsertDynamicForms()
        {
            try
            {
                var userId        = ClaimPrincipalFactory.GetUserId(User);
                var dynamicForms  = JsonSerializer.Deserialize <DynamiFormDto>(HttpContext.Request.Form["DynamicForms"]);
                var _dynamicForms = _mapper.Map <DynamicForms>(dynamicForms);
                _dynamicForms.Cdate   = DateTime.Now.Ticks;
                _dynamicForms.CuserId = userId;


                var fileList = HttpContext.Request.Form.Files.ToList();

                foreach (var uploadFileStatus in fileList.Select(file => FileManeger.FileUploader(file, 1, "DynamicFormImages")))
                {
                    if (uploadFileStatus.Status == 200)
                    {
                        var image = new DynamiFormImage
                        {
                            Cdate    = DateTime.Now.Ticks,
                            CuserId  = userId,
                            ImageUrl = uploadFileStatus.Path
                        };
                        _dynamicForms.DynamiFormImage.Add(image);
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 100);
                    }
                }

                _repository.DynamicForms.Create(_dynamicForms);
                _repository.Save();

                _logger.LogData(MethodBase.GetCurrentMethod(), _dynamicForms.Id, null);
                return(Ok(_dynamicForms.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod());
                return(BadRequest(e.Message));
            }
        }
 public IActionResult DeleteProductPackingImage(long productPackingImageId)
 {
     try
     {
         var image = _repository.ProductPackingTypeImage.FindByCondition(c => c.Id == productPackingImageId)
                     .FirstOrDefault();
         var deletedFile = image.ImageFileUrl;
         if (image == null)
         {
             return(NotFound());
         }
         _repository.ProductPackingTypeImage.Delete(image);
         _repository.Save();
         FileManeger.FileRemover(new List <string> {
             deletedFile
         });
         return(NoContent());
     }
     catch (Exception e)
     {
         return(BadRequest(""));
     }
 }
예제 #17
0
 private void tsmiAddExcel_Click(object sender, EventArgs e)
 {
     if (IsActiveChildProjectOverview)
     {
         try
         {
             ProjectOverview overview;
             overview = (ProjectOverview)this.ActiveMdiChild;
             if (MessageBox.Show("Do you whant to create a new Excel Document ?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
             }
             else
             {
                 overview.AddFile(new ProjectFile(FileManeger.OpenFile(ProjectFile.Type.Excel), ProjectFile.Type.Excel));
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Can't Add the file");
             Log.Error(ex.Message);
         }
     }
 }
        public IActionResult InsertFamousComments()
        {
            var famousCommentsDto = JsonSerializer.Deserialize <FamousCommentsDto>(HttpContext.Request.Form["FamousComments"]);
            var famousComments    = _mapper.Map <FamousComments>(famousCommentsDto);
            var CommentPic        = HttpContext.Request.Form.Files[0];
            var ProfilePic        = HttpContext.Request.Form.Files[1];

            var uploadFileStatus  = FileManeger.FileUploader(CommentPic, 1, "FamousCommentImages");
            var uploadFileStatus1 = FileManeger.FileUploader(ProfilePic, 1, "FamousCommentImages");

            if (uploadFileStatus.Status != 200 || uploadFileStatus1.Status != 200)
            {
                return(BadRequest("Internal server error"));
            }

            famousComments.CommentPic = uploadFileStatus.Path;
            famousComments.ProfilePic = uploadFileStatus1.Path;
            famousComments.CuserId    = ClaimPrincipalFactory.GetUserId(User);
            famousComments.Cdate      = DateTime.Now.Ticks;
            _repository.FamousComments.Create(famousComments);



            try
            {
                _repository.Save();
                return(Created("", famousComments));
            }
            catch (Exception e)
            {
                FileManeger.FileRemover(new List <string> {
                    uploadFileStatus.Path, uploadFileStatus1.Path
                });
                return(BadRequest(e.Message.ToString()));
            }
        }
예제 #19
0
        public IActionResult UpdateBuyCard(long buyCardId)
        {
            try
            {
                var userId = ClaimPrincipalFactory.GetUserId(User);


                var buycard      = JsonSerializer.Deserialize <InsertBuyCardDto>(HttpContext.Request.Form["BuyCard"]);
                var releventList = JsonSerializer.Deserialize <List <long> >(HttpContext.Request.Form["releventList"]);
                var product      = _repository.Product.FindByCondition(c => c.Id == buyCardId).FirstOrDefault();
                if (product == null)
                {
                    throw new BusinessException(XError.GetDataErrors.NotFound());
                }

                product.Mdate           = DateTime.Now.Ticks;
                product.MuserId         = userId;
                product.FinalStatusId   = 10;
                product.Description     = buycard.Description;
                product.Count           = buycard.FirstCount;
                product.FirstCount      = buycard.FirstCount;
                product.KeyWords        = buycard.KeyWords;
                product.MetaDescription = buycard.MetaDescription;
                product.MetaTitle       = buycard.MetaTitle;
                product.Name            = buycard.Name;
                product.Price           = buycard.Price;

                var tobedeletedImage = _repository.ProductImage.FindByCondition(c => c.ProductId == buyCardId).ToList();
                _repository.ProductImage.DeleteRange(tobedeletedImage);

                var tobedeletedRelative = _repository.RelatedProduct
                                          .FindByCondition(c => c.OriginProductId == buyCardId).ToList();
                _repository.RelatedProduct.DeleteRange(tobedeletedRelative);

                releventList.ForEach(c =>
                {
                    var pro = new RelatedProduct
                    {
                        CuserId         = ClaimPrincipalFactory.GetUserId(User),
                        Cdate           = DateTime.Now.Ticks,
                        DestinProductId = c
                    };
                    product.RelatedProductOriginProduct.Add(pro);
                });


                var fileList = HttpContext.Request.Form.Files.ToList();

                foreach (var uploadFileStatus in fileList.Select(file => FileManeger.FileUploader(file, 1, "BuyCardImages")))
                {
                    if (uploadFileStatus.Status == 200)
                    {
                        var image = new ProductImage
                        {
                            Cdate    = DateTime.Now.Ticks,
                            CuserId  = userId,
                            ImageUrl = uploadFileStatus.Path,
                        };
                        product.ProductImage.Add(image);
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 100);
                    }
                }

                _repository.Product.Update(product);
                _repository.Save();

                _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, buyCardId);
                return(Ok(General.Results_.SuccessMessage()));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), buyCardId);
                return(BadRequest(e.Message));
            }
        }
예제 #20
0
        public IActionResult InsertBuyCard()
        {
            try
            {
                var userId = ClaimPrincipalFactory.GetUserId(User);


                var buycard      = JsonSerializer.Deserialize <InsertBuyCardDto>(HttpContext.Request.Form["BuyCard"]);
                var releventList = JsonSerializer.Deserialize <List <long> >(HttpContext.Request.Form["releventList"]);

                var product = new Product
                {
                    Cdate         = DateTime.Now.Ticks,
                    CuserId       = userId,
                    FinalStatusId = 10,
                    CatProductId  = _repository.CatProduct
                                    .FindByCondition(c => c.Rkey == 1 && c.DaDate == null && c.Ddate == null).Select(c => c.Id)
                                    .FirstOrDefault(),
                    Description     = buycard.Description,
                    Count           = buycard.FirstCount,
                    FirstCount      = buycard.FirstCount,
                    KeyWords        = buycard.KeyWords,
                    MetaDescription = buycard.MetaDescription,
                    MetaTitle       = buycard.MetaTitle,
                    Name            = buycard.Name,
                    Price           = buycard.Price,
                    LastSeenDate    = DateTime.Now.Ticks,
                    SeenCount       = 0
                };


                releventList.ForEach(c =>
                {
                    var pro = new RelatedProduct
                    {
                        CuserId         = ClaimPrincipalFactory.GetUserId(User),
                        Cdate           = DateTime.Now.Ticks,
                        DestinProductId = c
                    };
                    product.RelatedProductOriginProduct.Add(pro);
                });


                var fileList = HttpContext.Request.Form.Files.ToList();

                foreach (var uploadFileStatus in fileList.Select(file => FileManeger.FileUploader(file, 1, "BuyCardImages")))
                {
                    if (uploadFileStatus.Status == 200)
                    {
                        var image = new ProductImage
                        {
                            Cdate    = DateTime.Now.Ticks,
                            CuserId  = userId,
                            ImageUrl = uploadFileStatus.Path,
                        };
                        product.ProductImage.Add(image);
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 100);
                    }
                }

                _repository.Product.Create(product);
                _repository.Save();

                _logger.LogData(MethodBase.GetCurrentMethod(), product.Id, null);
                return(Ok(product.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod());
                return(BadRequest(e.Message));
            }
        }
예제 #21
0
        public IActionResult EditProduct(long productId)
        {
            Product _product = JsonSerializer.Deserialize <Product>(HttpContext.Request.Form["Product"]);
            Seller  seller   = new Seller();
            var     userid   = ClaimPrincipalFactory.GetUserId(User);

            var product = _repository.Product.FindByCondition(c => c.Id.Equals(productId)).FirstOrDefault();

            if (product == null)
            {
                return(NotFound());
            }

            if (_product.SellerId == null || _product.SellerId == 0)
            {
                seller = _repository.Seller.FindByCondition(c => c.UserId == userid).FirstOrDefault();
            }
            else
            {
                seller = _repository.Seller.FindByCondition(c => c.Id == _product.SellerId).FirstOrDefault();
            }

            if (product.SellerId != seller.Id || product.CatProductId != _product.CatProductId)
            {
                var catProduct = _repository.CatProduct.FindByCondition(c => c.Id == _product.CatProductId)
                                 .FirstOrDefault();
                var counter = (_repository.Product
                               .FindByCondition(c => c.SellerId == seller.Id && c.CatProductId == catProduct.Id)
                               .Count() + 1).ToString();
                counter        = counter.PadLeft(3, '0');
                product.Coding = long.Parse(seller.SellerCode.ToString() + catProduct.Coding.ToString() + counter);
            }

            product.Name           = _product.Name;
            product.EnName         = _product.EnName;
            product.CatProductId   = _product.CatProductId;
            product.Coding         = _product.Coding;
            product.Price          = _product.Price;
            product.FirstCount     = _product.FirstCount;
            product.ProductMeterId = _product.ProductMeterId;
            product.Description    = _product.Description;
            product.SellerId       = seller.Id;
            product.MuserId        = userid;
            product.Mdate          = DateTime.Now.Ticks;

            if (HttpContext.Request.Form.Files.Count > 0)
            {
                var coverImageUrl = HttpContext.Request.Form.Files[0];
                var deletedFile   = product.CoverImageUrl;
                FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(coverImageUrl, 1, "ProductImages");
                if (uploadFileStatus.Status == 200)
                {
                    product.CoverImageUrl = uploadFileStatus.Path;
                    _repository.Product.Update(product);
                    try
                    {
                        _repository.Save();
                        FileManeger.FileRemover(new List <string> {
                            deletedFile
                        });

                        return(NoContent());
                    }
                    catch (Exception e)
                    {
                        FileManeger.FileRemover(new List <string> {
                            uploadFileStatus.Path
                        });
                        return(BadRequest("Internal server error"));
                    }
                }
                else
                {
                    return(BadRequest("Internal server error"));
                }
            }
            else
            {
                _repository.Product.Update(product);
                try
                {
                    _repository.Save();

                    return(NoContent());
                }
                catch (Exception e)
                {
                    return(BadRequest("Internal server error"));
                }
            }
        }
예제 #22
0
        public IActionResult UpdatePackage([FromForm] InsertPackageDto input, [FromForm] FormFileCollection fileList)
        {
            try
            {
                var validator = new ParamValidator();
                validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان"))
                .ValidateNull(input.Price, General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت"))
                .ValidateNull(input.PackageId, General.Messages_.NullInputMessages_.GeneralNullMessage("آیدی پکیج"))
                .Throw(General.Results_.FieldNullErrorCode());

                if (input.ProductWithPriceList.Count == 0)
                {
                    throw new BusinessException("محصولی برای پکیج انتخاب نشده است.", 4001);
                }

                var product = _repository.Product.FindByCondition(c => c.Id == input.PackageId.Value && c.Ddate == null)
                              .FirstOrDefault();

                if (product == null)
                {
                    throw new BusinessException(XError.GetDataErrors.NotFound());
                }

                product.Name            = input.Name;
                product.Price           = input.Price;
                product.MetaDescription = input.MetaDesc;
                product.KeyWords        = input.KeyWord;
                product.MetaTitle       = input.MetaTitle;
                product.Mdate           = DateTime.Now.Ticks;
                product.LanguageId      = input.LanguageId;
                product.MuserId         = ClaimPrincipalFactory.GetUserId(User);


                var tobeDeletedProductPackeage = _repository.ProductPackage
                                                 .FindByCondition(c => c.MainProductId == product.Id).ToList();
                tobeDeletedProductPackeage.ForEach(c =>
                {
                    c.Ddate   = DateTime.Now.Ticks;
                    c.DuserId = ClaimPrincipalFactory.GetUserId(User);
                });

                _repository.ProductPackage.UpdateRange(tobeDeletedProductPackeage);

                input.ProductWithPriceList.ForEach(c =>
                {
                    var newProductPackage = new ProductPackage()
                    {
                        Cdate        = DateTime.Now.Ticks,
                        CuserId      = ClaimPrincipalFactory.GetUserId(User),
                        DepProductId = c.ProductId,
                        Price        = c.Price
                    };

                    product.ProductPackageDepProduct.Add(newProductPackage);
                });

                var tobeDeletedProductImage = _repository.ProductImage
                                              .FindByCondition(c => c.ProductId == product.Id).ToList();
                tobeDeletedProductImage.ForEach(c =>
                {
                    c.Ddate   = DateTime.Now.Ticks;
                    c.DuserId = ClaimPrincipalFactory.GetUserId(User);
                });

                _repository.ProductImage.UpdateRange(tobeDeletedProductImage);

                fileList.ForEach(c =>
                {
                    short fileType = 1;
                    if (FileManeger.IsVideo(c))
                    {
                        fileType = 2;
                    }
                    var uploadFileStatus = FileManeger.FileUploader(c, fileType, "ProductPackage");
                    if (uploadFileStatus.Status == 200)
                    {
                        var newProductImage = new ProductImage
                        {
                            Cdate    = DateTime.Now.Ticks,
                            CuserId  = ClaimPrincipalFactory.GetUserId(User),
                            ImageUrl = uploadFileStatus.Path,
                            FileType = fileType
                        };
                        product.ProductImage.Add(newProductImage);
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 4009);
                    }
                });

                _repository.Product.Update(product);
                _repository.Save();
                _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, input, "****");
                return(Ok(General.Results_.SuccessMessage()));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), input, "****");
                return(BadRequest(e.Message));
            }
        }
예제 #23
0
        public IActionResult UpdatePackingType()
        {
            try
            {
                var packingType = JsonSerializer.Deserialize <PackingType>(HttpContext.Request.Form["PackingType"]);
                var validator   = new ParamValidator();
                validator.ValidateNull(packingType.Name,
                                       General.Messages_.NullInputMessages_.GeneralNullMessage("نام"))
                .ValidateNull(packingType.Price,
                              General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت"))
                .ValidateNull(packingType.Id,
                              General.Messages_.NullInputMessages_.GeneralNullMessage("آیدی"));

                var photo     = HttpContext.Request.Form.Files.GetFile("Photo");
                var video     = HttpContext.Request.Form.Files.GetFile("Video");
                var photopath = "";
                var videopath = "";
                if (photo != null)
                {
                    var uploadFileStatus = FileManeger.FileUploader(photo, 1, "PackingTypeImages");
                    if (uploadFileStatus.Status == 200)
                    {
                        photopath = uploadFileStatus.Path;
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 100);
                    }
                }

                if (video != null)
                {
                    var uploadFileStatus1 = FileManeger.FileUploader(video, 2, "PackingTypeVideo");
                    if (uploadFileStatus1.Status == 200)
                    {
                        videopath = uploadFileStatus1.Path;
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus1.Path, 100);
                    }
                }


                var packing = _repository.PackingType.FindByCondition(c => c.Id == packingType.Id)
                              .Include(c => c.PackingTypeImage).FirstOrDefault();

                if (packing == null)
                {
                    throw new BusinessException(XError.GetDataErrors.NotFound());
                }

                packing.MuserId = DateTime.Now.Ticks;
                packing.Mdate   = ClaimPrincipalFactory.GetUserId(User);

                if (photopath != "")
                {
                    var toBeDeletedImage = packing.PackingTypeImage.FirstOrDefault(c => c.FileType == 2);
                    if (toBeDeletedImage != null)
                    {
                        _repository.PackingTypeImage.Delete(toBeDeletedImage);
                    }

                    var packingtypeImge = new PackingTypeImage
                    {
                        ImageFileUrl = photopath,
                        Cdate        = DateTime.Now.Ticks,
                        CuserId      = ClaimPrincipalFactory.GetUserId(User),
                        FileType     = 1
                    };
                    packing.PackingTypeImage.Add(packingtypeImge);
                }

                if (photopath != "")
                {
                    var toBeDeletedVideo = packing.PackingTypeImage.FirstOrDefault(c => c.FileType == 1);
                    if (toBeDeletedVideo != null)
                    {
                        _repository.PackingTypeImage.Delete(toBeDeletedVideo);
                    }
                    var packingtypeVideo = new PackingTypeImage
                    {
                        ImageFileUrl = videopath,
                        Cdate        = DateTime.Now.Ticks,
                        CuserId      = ClaimPrincipalFactory.GetUserId(User),
                        FileType     = 2
                    };
                    packing.PackingTypeImage.Add(packingtypeVideo);
                }

                _repository.PackingType.Update(packing);
                _repository.Save();
                _logger.LogData(MethodBase.GetCurrentMethod(), packing.Id, null);
                return(Ok(packing.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod());
                return(BadRequest(e.Message));
            }
        }
예제 #24
0
        public IActionResult InsertPackingType()
        {
            try
            {
                var packingType = JsonSerializer.Deserialize <PackingType>(HttpContext.Request.Form["PackingType"]);
                var validator   = new ParamValidator();
                validator.ValidateNull(packingType.Name,
                                       General.Messages_.NullInputMessages_.GeneralNullMessage("نام"))
                .ValidateNull(packingType.Price,
                              General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت"));

                var photo     = HttpContext.Request.Form.Files.GetFile("Photo");
                var video     = HttpContext.Request.Form.Files.GetFile("Video");
                var photopath = "";
                var videopath = "";
                if (photo != null)
                {
                    var uploadFileStatus = FileManeger.FileUploader(photo, 1, "PackingTypeImages");
                    if (uploadFileStatus.Status == 200)
                    {
                        photopath = uploadFileStatus.Path;
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 100);
                    }
                }

                if (video != null)
                {
                    var uploadFileStatus1 = FileManeger.FileUploader(video, 2, "PackingTypeVideo");
                    if (uploadFileStatus1.Status == 200)
                    {
                        videopath = uploadFileStatus1.Path;
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus1.Path, 100);
                    }
                }


                packingType.Cdate   = DateTime.Now.Ticks;
                packingType.CuserId = ClaimPrincipalFactory.GetUserId(User);

                if (photopath != "")
                {
                    var packingtypeImge = new PackingTypeImage
                    {
                        ImageFileUrl = photopath,
                        Cdate        = DateTime.Now.Ticks,
                        CuserId      = ClaimPrincipalFactory.GetUserId(User),
                        FileType     = 2
                    };
                    packingType.PackingTypeImage.Add(packingtypeImge);
                }

                if (photopath != "")
                {
                    var packingtypeVideo = new PackingTypeImage
                    {
                        ImageFileUrl = videopath,
                        Cdate        = DateTime.Now.Ticks,
                        CuserId      = ClaimPrincipalFactory.GetUserId(User),
                        FileType     = 1
                    };
                    packingType.PackingTypeImage.Add(packingtypeVideo);
                }

                _repository.PackingType.Create(packingType);
                _repository.Save();
                _logger.LogData(MethodBase.GetCurrentMethod(), packingType.Id, null);
                return(Ok(packingType.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod());
                return(BadRequest(e.Message));
            }
        }
예제 #25
0
        public IActionResult EditSlider(long sliderId)
        {
            Slider _slider = JsonSerializer.Deserialize <Slider>(HttpContext.Request.Form["Slider"]);
            var    slider  = _repository.Slider.FindByCondition(c => c.Id.Equals(sliderId)).FirstOrDefault();

            if (slider.Equals(null))
            {
                _logger.LogError($"Slider with id: {sliderId}, hasn't been found in db.");
                return(NotFound());
            }

            if (HttpContext.Request.Form.Files.Count > 0)
            {
                var imageUrl    = HttpContext.Request.Form.Files[0];
                var deletedFile = slider.ImageUrl;
                FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(imageUrl, 1, "SliderImages");
                if (uploadFileStatus.Status == 200)
                {
                    slider.ImageHurl         = _slider.ImageHurl;
                    slider.ImageUrl          = uploadFileStatus.Path;
                    slider.LinkUrl           = _slider.LinkUrl;
                    slider.Mdate             = timeTick;
                    slider.MuserId           = userid;
                    slider.Rorder            = _slider.Rorder;
                    slider.SliderPlaceTypeId = _slider.SliderPlaceTypeId;
                    slider.Title             = _slider.Title;
                    _repository.Slider.Update(slider);
                    try
                    {
                        _repository.Save();
                        FileManeger.FileRemover(new List <string> {
                            deletedFile
                        });
                        _logger.LogInfo($"Update Slider In database ById={sliderId}");
                        return(Ok(""));
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"Something went wrong Update Slider To database: {e.Message}");
                        FileManeger.FileRemover(new List <string> {
                            uploadFileStatus.Path
                        });
                        return(BadRequest("Internal server error"));
                    }
                }
                else
                {
                    _logger.LogError($"Something went wrong Update Slider To database: {uploadFileStatus.Path}");
                    return(BadRequest("Internal server error"));
                }
            }
            else
            {
                slider.ImageHurl         = _slider.ImageHurl;
                slider.LinkUrl           = _slider.LinkUrl;
                slider.Mdate             = timeTick;
                slider.MuserId           = userid;
                slider.Rorder            = _slider.Rorder;
                slider.SliderPlaceTypeId = _slider.SliderPlaceTypeId;
                slider.Title             = _slider.Title;
                _repository.Slider.Update(slider);
                try
                {
                    _repository.Save();
                    _logger.LogInfo($"Update Slider In database ById={sliderId}");
                    return(Ok(""));
                }
                catch (Exception e)
                {
                    _logger.LogError($"Something went wrong Update Slider To database: {e.Message}");
                    return(BadRequest("Internal server error"));
                }
            }
        }
예제 #26
0
        public IActionResult InsertProduct()
        {
            var coverpath    = "";
            var downloadpath = "";

            try
            {
                var product       = JsonSerializer.Deserialize <Product>(HttpContext.Request.Form["Product"]);
                var releventList  = JsonSerializer.Deserialize <List <long> >(HttpContext.Request.Form["releventList"]);
                var coverImageUrl = HttpContext.Request.Form.Files.GetFile("CoverImage");
                var downloadLink  = HttpContext.Request.Form.Files.GetFile("DownloadLink");



                if (coverImageUrl != null)
                {
                    var uploadFileStatus = FileManeger.FileUploader(coverImageUrl, 1, "ProductImages");
                    if (uploadFileStatus.Status == 200)
                    {
                        coverpath = uploadFileStatus.Path;
                    }
                    else
                    {
                        return(BadRequest(uploadFileStatus.Path));
                    }
                }
                if (downloadLink != null && product.VirtualProduct.Value)
                {
                    var uploadFileStatus = FileManeger.FileUploader(downloadLink, 3, "ProductFiles");
                    if (uploadFileStatus.Status == 200)
                    {
                        downloadpath = uploadFileStatus.Path;
                    }
                    else
                    {
                        return(BadRequest(uploadFileStatus.Path));
                    }
                }


                product.CoverImageUrl = coverpath;
                product.DownloadLink  = downloadpath;
                product.CuserId       = ClaimPrincipalFactory.GetUserId(User);
                product.Cdate         = DateTime.Now.Ticks;

                var counter = (_repository.Product
                               .FindByCondition(c => c.Coding.ToString().Substring(0, 9) == product.Coding.ToString())
                               .Count() + 1).ToString();
                counter = counter.PadLeft(3, '0');

                product.Coding = Convert.ToInt64(string.Concat(product.Coding.ToString(), counter));

                product.LastSeenDate = DateTime.Now.Ticks;
                product.SeenCount    = 0;


                var parameters = _repository.CatProductParameters
                                 .FindByCondition(c => c.CatProductId == product.CatProductId).ToList();

                parameters.ForEach(c =>
                {
                    var paramss = new ProductCatProductParameters
                    {
                        CatProductParametersId = c.Id,
                        CuserId = ClaimPrincipalFactory.GetUserId(User),
                        Cdate   = DateTime.Now.Ticks
                    };
                    product.ProductCatProductParameters.Add(paramss);
                });
                releventList.ForEach(c =>
                {
                    var pro = new RelatedProduct
                    {
                        CuserId         = ClaimPrincipalFactory.GetUserId(User),
                        Cdate           = DateTime.Now.Ticks,
                        DestinProductId = c
                    };
                    product.RelatedProductOriginProduct.Add(pro);
                });

                _repository.Product.Create(product);


                _repository.Save();

                return(NoContent());
            }
            catch (Exception e)
            {
                FileManeger.FileRemover(new List <string> {
                    coverpath, downloadpath
                });
                _logger.LogError(e, MethodBase.GetCurrentMethod());
                return(BadRequest(e.Message));
            }
        }
예제 #27
0
        public IActionResult EditProduct(long productId)
        {
            Product _product = JsonSerializer.Deserialize <Product>(HttpContext.Request.Form["Product"]);
            Seller  seller   = new Seller();

            userid = User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).Select(x => x.Value).SingleOrDefault();

            var product = _repository.Product.FindByCondition(c => c.Id.Equals(productId)).FirstOrDefault();

            if (product == null)
            {
                _logger.LogError($"Product with id: {productId}, hasn't been found in db.");
                return(NotFound());
            }

            if (_product.SellerId == null || _product.SellerId == 0)
            {
                seller = _repository.Seller.FindByCondition(c => c.UserId == userid).FirstOrDefault();
            }
            else
            {
                seller = _repository.Seller.FindByCondition(c => c.Id == _product.SellerId).FirstOrDefault();
            }

            if (product.SellerId != seller.Id || product.CatProductId != _product.CatProductId)
            {
                var catProduct = _repository.CatProduct.FindByCondition(c => c.Id == _product.CatProductId)
                                 .FirstOrDefault();
                var counter = (_repository.Product
                               .FindByCondition(c => c.SellerId == seller.Id && c.CatProductId == catProduct.Id)
                               .Count() + 1).ToString();
                counter        = counter.PadLeft(3, '0');
                product.Coding = long.Parse(seller.SellerCode.ToString() + catProduct.Coding.ToString() + counter);
            }

            product.Name           = _product.Name;
            product.EnName         = _product.EnName;
            product.CatProductId   = _product.CatProductId;
            product.Coding         = _product.Coding;
            product.Price          = _product.Price;
            product.FirstCount     = _product.FirstCount;
            product.ProductMeterId = _product.ProductMeterId;
            product.Description    = _product.Description;
            product.SellerId       = seller.Id;
            product.MuserId        = userid;
            product.Mdate          = timeTick;

            if (HttpContext.Request.Form.Files.Count > 0)
            {
                var coverImageUrl = HttpContext.Request.Form.Files[0];
                var deletedFile   = product.CoverImageUrl;
                FileManeger.UploadFileStatus uploadFileStatus = FileManeger.FileUploader(coverImageUrl, 1, "ProductImages");
                if (uploadFileStatus.Status == 200)
                {
                    product.CoverImageUrl = uploadFileStatus.Path;
                    _repository.Product.Update(product);
                    try
                    {
                        _repository.Save();
                        FileManeger.FileRemover(new List <string> {
                            deletedFile
                        });
                        _logger.LogInfo($"Update Product In database ById={productId}");
                        return(Ok(""));
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"Something went wrong Update Product To database: {e.Message}");
                        FileManeger.FileRemover(new List <string> {
                            uploadFileStatus.Path
                        });
                        return(BadRequest("Internal server error"));
                    }
                }
                else
                {
                    _logger.LogError($"Something went wrong Update Product To database: {uploadFileStatus.Path}");
                    return(BadRequest("Internal server error"));
                }
            }
            else
            {
                _repository.Product.Update(product);
                try
                {
                    _repository.Save();
                    _logger.LogInfo($"Update Product In database ById={productId}");
                    return(Ok(""));
                }
                catch (Exception e)
                {
                    _logger.LogError($"Something went wrong Update Product To database: {e.Message}");
                    return(BadRequest("Internal server error"));
                }
            }
        }
예제 #28
0
        public IActionResult InsertPackage([FromForm] InsertPackageDto input, [FromForm] FormFileCollection fileList)
        {
            try
            {
                var validator = new ParamValidator();
                validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان"))
                .ValidateNull(input.Price, General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت"))
                .Throw(General.Results_.FieldNullErrorCode());

                if (input.ProductWithPriceList.Count == 0)
                {
                    throw new BusinessException("محصولی برای پکیج انتخاب نشده است.", 4001);
                }


                var counter = (_repository.Product
                               .FindByCondition(c => c.Coding.ToString().Substring(0, 8) == "11223344")
                               .Count() + 1).ToString();
                counter = counter.PadLeft(4, '0');

                var newproduct = new Product
                {
                    Name            = input.Name,
                    Price           = input.Price,
                    MetaDescription = input.MetaDesc,
                    KeyWords        = input.KeyWord,
                    MetaTitle       = input.MetaTitle,
                    Coding          = long.Parse("11223344" + counter),
                    IsPackage       = true,
                    Cdate           = DateTime.Now.Ticks,
                    CuserId         = ClaimPrincipalFactory.GetUserId(User)
                };

                input.ProductWithPriceList.ForEach(c =>
                {
                    var newProductPackage = new ProductPackage()
                    {
                        Cdate        = DateTime.Now.Ticks,
                        CuserId      = ClaimPrincipalFactory.GetUserId(User),
                        DepProductId = c.ProductId,
                        Price        = c.Price
                    };

                    newproduct.ProductPackageDepProduct.Add(newProductPackage);
                });

                fileList.ForEach(c =>
                {
                    short fileType = 1;
                    if (FileManeger.IsVideo(c))
                    {
                        fileType = 2;
                    }
                    var uploadFileStatus = FileManeger.FileUploader(c, fileType, "ProductPackage");
                    if (uploadFileStatus.Status == 200)
                    {
                        var newProductImage = new ProductImage
                        {
                            Cdate    = DateTime.Now.Ticks,
                            CuserId  = ClaimPrincipalFactory.GetUserId(User),
                            ImageUrl = uploadFileStatus.Path,
                            FileType = fileType
                        };
                        newproduct.ProductImage.Add(newProductImage);
                    }
                    else
                    {
                        throw new BusinessException(uploadFileStatus.Path, 4009);
                    }
                });

                _repository.Product.Create(newproduct);
                _repository.Save();
                _logger.LogData(MethodBase.GetCurrentMethod(), newproduct.Id, null, input, "****");
                return(Ok(newproduct.Id));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), input, "****");
                return(BadRequest(e.Message));
            }
        }
예제 #29
0
        public IActionResult UpdateSlider()
        {
            var sliderdto = JsonSerializer.Deserialize <SliderDto>(HttpContext.Request.Form["Slider"]);
            var _slider   = _mapper.Map <Slider>(sliderdto);
            var slider    = _repository.Slider.FindByCondition(c => c.Id.Equals(_slider.Id)).FirstOrDefault();

            if (slider == null)
            {
                return(NotFound());
            }

            if (HttpContext.Request.Form.Files.Count > 0)
            {
                var imageUrl         = HttpContext.Request.Form.Files[0];
                var deletedFile      = slider.ImageUrl;
                var uploadFileStatus = FileManeger.FileUploader(imageUrl, 1, "SliderImages");
                if (uploadFileStatus.Status != 200)
                {
                    return(BadRequest("Internal server error"));
                }
                slider.ImageHurl     = _slider.ImageHurl;
                slider.ImageUrl      = uploadFileStatus.Path;
                slider.LinkUrl       = _slider.LinkUrl;
                slider.MuserId       = ClaimPrincipalFactory.GetUserId(User);
                slider.Mdate         = DateTime.Now.Ticks;
                slider.Rorder        = _slider.Rorder;
                slider.SliderPlaceId = _slider.SliderPlaceId;
                slider.Title         = _slider.Title;
                _repository.Slider.Update(slider);



                try
                {
                    _repository.Save();
                    FileManeger.FileRemover(new List <string> {
                        deletedFile
                    });

                    return(NoContent());
                }
                catch (Exception e)
                {
                    FileManeger.FileRemover(new List <string> {
                        uploadFileStatus.Path
                    });
                    return(BadRequest("Internal server error"));
                }
            }


            slider.ImageHurl     = _slider.ImageHurl;
            slider.LinkUrl       = _slider.LinkUrl;
            slider.MuserId       = ClaimPrincipalFactory.GetUserId(User);
            slider.Mdate         = DateTime.Now.Ticks;
            slider.Rorder        = _slider.Rorder;
            slider.SliderPlaceId = _slider.SliderPlaceId;
            slider.Title         = _slider.Title;
            _repository.Slider.Update(slider);
            try
            {
                _repository.Save();
                return(NoContent());
            }
            catch (Exception e)
            {
                return(BadRequest("Internal server error"));
            }
        }
예제 #30
0
        public IActionResult UpdateDynamicForms(long dynamicFormsId)
        {
            try
            {
                var userId        = ClaimPrincipalFactory.GetUserId(User);
                var dynamicForms  = JsonSerializer.Deserialize <DynamiFormDto>(HttpContext.Request.Form["DynamicForms"]);
                var _dynamicForms = _repository.DynamicForms.FindByCondition(c => c.Id == dynamicFormsId)
                                    .FirstOrDefault();
                if (_dynamicForms == null)
                {
                    throw new BusinessException(XError.GetDataErrors.NotFound());
                }
                _dynamicForms.Mdate           = DateTime.Now.Ticks;
                _dynamicForms.MuserId         = userId;
                _dynamicForms.Description     = dynamicForms.Description;
                _dynamicForms.DescriptionMeta = dynamicForms.DescriptionMeta;
                _dynamicForms.Title           = dynamicForms.Title;
                _dynamicForms.TitleMetaData   = dynamicForms.TitleMetaData;
                _dynamicForms.KeyWords        = dynamicForms.KeyWords;
                _dynamicForms.LanguageId      = dynamicForms.LanguageId;



                var fileList = HttpContext.Request.Form.Files.ToList();
                if (fileList.Count > 0)
                {
                    foreach (var uploadFileStatus in fileList.Select(file => FileManeger.FileUploader(file, 1, "DynamicFormImages")))
                    {
                        var tobedeletedList = _repository.DynamiFormImage
                                              .FindByCondition(c => c.DynamicFormId == dynamicFormsId).ToList();
                        foreach (var item in tobedeletedList)
                        {
                            item.Ddate   = DateTime.Now.Ticks;
                            item.DuserId = userId;
                            _repository.DynamiFormImage.Update(item);
                        }
                        if (uploadFileStatus.Status == 200)
                        {
                            var image = new DynamiFormImage
                            {
                                Cdate    = DateTime.Now.Ticks,
                                CuserId  = userId,
                                ImageUrl = uploadFileStatus.Path
                            };
                            _dynamicForms.DynamiFormImage.Add(image);
                        }
                        else
                        {
                            throw new BusinessException(uploadFileStatus.Path, 100);
                        }
                    }
                }


                _repository.DynamicForms.Create(_dynamicForms);
                _repository.Save();

                _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, dynamicFormsId);
                return(Ok(General.Results_.SuccessMessage()));
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), dynamicFormsId);
                return(BadRequest(e.Message));
            }
        }