コード例 #1
0
        /// <summary>
        /// ثبت یک آیتم در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که از سمت کلاینت در حال پاس دادن آن هستیم</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> UpdateAsync(SlideShowUpdateViewModel model)
        {
            try
            {
                var entity = Mapper.Map <SlideShow>(model);

                #region ذخیره فایل مورد نظر

                if (model.ImageFile != null)
                {
                    //حذف فایل قبلی
                    MFile.Delete(entity.ImgAddress);
                    // ذخیره فایل جدید
                    entity.ImgAddress = MFile.Save(model.ImageFile, "Uploads/SlideShow");
                }

                #endregion

                await UpdateAsync(entity);

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e)
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #2
0
        public async Task <int> UpdateAsync(ProductPackageUpdateViewModel vm, IFormFile file)
        {
            var model = GetById(vm.Id);

            if (file != null)
            {
                if (vm.IndexPic != null)
                {
                    try
                    {
                        var WebContent = _hostingEnvironment.WebRootPath;

                        System.IO.File.Delete(WebContent + FilePath.productPackage.GetDescription());
                    }
                    catch (Exception)
                    {
                        return(0);
                    }
                }
                vm.IndexPic = await MFile.Save(file, FilePath.productPackage.GetDescription());
            }
            else
            {
                vm.IndexPic = model.IndexPic;
            }

            Mapper.Map(vm, model);

            await DbContext.SaveChangesAsync();

            return(model.Id);
        }
コード例 #3
0
        public async Task <int> UpdateProduct(DataLayer.ViewModels.Products.ProductUpdateViewModel vm, IFormFile file)
        {
            if (file != null)
            {
                if (vm.IndexPic != null)
                {
                    var WebContent = _hostingEnvironment.WebRootPath;
                    if (vm.IndexPic != "Images/no-Pic.jpg")
                    {
                        System.IO.File.Delete(WebContent + FilePath.Product.GetDescription());
                    }
                }

                vm.IndexPic = await MFile.Save(file, FilePath.Product.GetDescription());
            }


            var model = GetById(vm.Id);

            if (file == null)
            {
                vm.IndexPic = model.IndexPic;
            }
            Mapper.Map(vm, model);

            DbContext.SaveChanges();

            return(model.Id);
        }
コード例 #4
0
        public async Task <SweetAlertExtenstion> UpdateAsync(NewsUpdateViewModel model)
        {
            try
            {
                var entity = await GetByIdAsync(model.Id);

                entity = (News)Mapper.Map(model, entity, typeof(NewsUpdateViewModel), typeof(News));

                #region ذخیره فایل مورد نظر

                if (model.ImageFile != null)
                {
                    //حذف فایل قبلی
                    await MFile.Delete(entity.ImageAddress);

                    // ذخیره فایل جدید
                    entity.ImageAddress = await MFile.Save(model.ImageFile, "Uploads/NewsImages");
                }

                #endregion

                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e)
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #5
0
        /// <summary>
        /// ویرایش یک آیتم
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> UpdateAsync(SubProjectUpdateViewModel model)
        {
            try
            {
                var entity = Mapper.Map <SubProject>(model);

                #region InsertFiles

                #region Book Or Sheet
                if (model.BookOrSeetAddress != null)
                {
                    await MFile.Delete(model.BookOrSeet);

                    entity.BookOrSeet = await MFile.Save(model.BookOrSeetAddress, "Uploads/BookOrSeet");
                }
                #endregion

                #region Book Cover
                if (model.BookCoverAddress != null)
                {
                    await MFile.Delete(model.BookCover);

                    entity.BookCover = await MFile.Save(model.BookCoverAddress, "Uploads/BookCover");
                }
                #endregion

                #endregion

                if (model.SubProjectType == DataLayer.SSOT.ProjectTypeSSOT.Sheet)
                {
                    model.BindingNumber     = null;
                    model.BindingType       = null;
                    model.BookCoverColor    = null;
                    model.BookCoverMaterial = null;
                    model.BookCover         = null;
                }

                //// TODO
                //if (model.Size != DataLayer.SSOT.SizeSSOT.Cutsom)
                //{
                //    model.Width = null;
                //    model.Height = null;
                //}

                Entities.Update(entity);
                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e)
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #6
0
        public async Task <int> CreateAsync(ProductPackageInsertViewModel vm, IFormFile file)
        {
            vm.IndexPic = await MFile.Save(file, FilePath.productPackage.GetDescription());

            var mapModel = Map(vm);

            mapModel.IsManager = true;

            await AddAsync(mapModel);

            return(mapModel.Id);
        }
コード例 #7
0
        //public async Task SetUserClaims(string username)
        //{
        //    var userinfo = await GetByConditionAsyncTracked(a => a.UserName == username);

        //    var claimsidentity = new List<Claim>()
        //        {
        //                new Claim("FirstName", userinfo.FirstName ?? ""),
        //                new Claim("LastName",  userinfo.LastName ?? ""),
        //                new Claim("FullName",  userinfo.FirstName + " "+ userinfo.LastName),
        //                new Claim("UserProfile" , userinfo.ProfilePic ?? "/Uploads/UserImage/NoPhoto.jpg")
        //                //...
        //        };


        //    await _userClaimsRepository.RemoveClamsByUserId(userinfo.Id);
        //    await _userManager.AddClaimsAsync(userinfo, claimsidentity);

        //}

        /// <summary>
        /// ویرایش عکس یک کاربر
        /// </summary>
        /// <param name="UserId">شماره کاربری</param>
        /// <param name="profilePic">عکس جدید کاربر</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> UpdateProfilePic(int UserId, IFormFile profilePic)
        {
            try
            {
                var entity = await GetByIdAsync(UserId);

                MFile.Delete(entity.ProfilePic);
                entity.ProfilePic = MFile.Save(profilePic, "Uploads/UserImage");
                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok("عملیات با موفقیت انجام شد"));
            }
            catch
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #8
0
        public async Task <SweetAlertExtenstion> InsertCar(CarTransportationInsertViewModel model, IFormFile file)
        {
            if (file == null)
            {
                model.Pic = "Images/no-Pic.jpg";
            }
            else
            {
                model.Pic = await MFile.Save(file, FilePath.Cars.GetDescription());
            }

            var result = model.ToEntity();

            await AddAsync(result);

            return(SweetAlertExtenstion.Ok());
        }
コード例 #9
0
        public async Task <int> SubmitProduct(DataLayer.ViewModels.Products.ProductInsertViewModel vm, IFormFile file)
        {
            if (file == null)
            {
                vm.IndexPic = "Images/no-Pic.jpg";
            }
            else
            {
                vm.IndexPic = await MFile.Save(file, FilePath.Product.GetDescription());
            }

            var mapModel = Map(vm);

            await AddAsync(mapModel);

            return(mapModel.Id);
        }
コード例 #10
0
        /// <summary>
        /// ثبت یک آیتم در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که از سمت کلاینت در حال پاس دادن آن هستیم</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> AddAsync(SubProjectInsertViewModel model)
        {
            try
            {
                var entity = Mapper.Map <SubProject>(model);

                #region InsertFiles

                #region Book Or Sheet
                entity.BookOrSeet = await MFile.Save(model.BookOrSeetAddress, "Uploads/BookOrSeet");

                #endregion

                #region Book Cover
                if (model.BookCoverAddress != null)
                {
                    entity.BookCover = await MFile.Save(model.BookCoverAddress, "Uploads/BookCover");
                }
                #endregion

                #endregion

                if (entity.SubProjectType == DataLayer.SSOT.ProjectTypeSSOT.Book)
                {
                    //TODO check .PDF
                    //if (Path.GetExtension(entity.BookOrSeet).ToLower() == "pdf")
                    {
                        string    filePath  = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/" + entity.BookOrSeet);
                        PdfReader pdfReader = new PdfReader(filePath);
                        entity.BookPageNumber = pdfReader.NumberOfPages;
                    }
                }

                await Entities.AddAsync(entity);

                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e)
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #11
0
        /// <summary>
        /// ثبت اطلاعات در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که باید به این تابع پاس داده شود  تا بتوان آن را ذخیره کرد</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> Insert(InsertNewsListView model)
        {
            try
            {
                var entity = Mapper.Map <News>(model);

                await _newsGroupRepository.AddAsync(new DataLayer.ViewModels.NewsGroup.NewsGroupInsertViewModel
                {
                    Title = "12"
                });

                #region ذخیره فایل مورد نظر

                entity.ImageAddress = await MFile.Save(model.ImageFile, "Uploads/NewsImages");

                #endregion
                await _newsGroupRepository.AddAsync(new DataLayer.ViewModels.NewsGroup.NewsGroupInsertViewModel
                {
                    Title = "13"
                });

                entity.Date = DateTime.Now;

                var result1 = await _newsGroupRepository.AddAsync(new DataLayer.ViewModels.NewsGroup.NewsGroupInsertViewModel
                {
                    Title = DateTime.Now.ToString()
                });
                await AddAsync(entity);

                await _newsGroupRepository.AddAsync(new DataLayer.ViewModels.NewsGroup.NewsGroupInsertViewModel
                {
                    Title = "14"
                });

                return(SweetAlertExtenstion.Ok());
            }
            catch
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #12
0
        public async Task <SweetAlertExtenstion> UpdateInfo(SiteInfoUpdateViewModel vm)
        {
            var entity = await TableNoTracking.SingleOrDefaultAsync();

            if (vm.LogoFile != null)
            {
                entity.Logo = await MFile.Save(vm.LogoFile, "Uploads/SiteSetting");
            }

            if (vm.BackGroudLoginPageFile != null)
            {
                entity.BackGroudLoginPage = await MFile.Save(vm.BackGroudLoginPageFile, "Uploads/SiteSetting");
            }

            entity.SiteName = vm.SiteName;

            Entities.Update(entity);
            await DbContext.SaveChangesAsync();

            return(SweetAlertExtenstion.Ok());
        }
コード例 #13
0
        /// <summary>
        /// ثبت یک آیتم در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که از سمت کلاینت در حال پاس دادن آن هستیم</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> AddAsync(SlideShowInsertViewModel model)
        {
            try
            {
                var entity = Mapper.Map <SlideShow>(model);

                #region ذخیره فایل مورد نظر

                entity.ImgAddress = MFile.Save(model.ImageFile, "Uploads/SlideShow");

                #endregion

                await AddAsync(entity);

                return(SweetAlertExtenstion.Ok());
            }
            catch
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #14
0
        /// <summary>
        /// ثبت اطلاعات در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که باید به این تابع پاس داده شود  تا بتوان آن را ذخیره کرد</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> Insert(InsertLogoManufactoryListView model)
        {
            try
            {
                var entity = Mapper.Map <LogoManufactory>(model);

                #region ذخیره فایل مورد نظر

                entity.AddressImg = await MFile.Save(model.ImageFile, "Uploads/LogoManufactoryImages");

                #endregion


                await AddAsync(entity);

                return(SweetAlertExtenstion.Ok());
            }
            catch
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #15
0
        /// <summary>
        /// ثبت اطلاعات در جدول مورد نظر
        /// </summary>
        /// <param name="model">مدلی که باید به این تابع پاس داده شود  تا بتوان آن را ذخیره کرد</param>
        /// <returns></returns>
        public async Task <SweetAlertExtenstion> Insert(InsertNewsListView model)
        {
            try
            {
                var entity = Mapper.Map <News>(model);

                #region ذخیره فایل مورد نظر

                entity.ImageAddress = await MFile.Save(model.ImageFile, "Uploads/NewsImages");

                #endregion

                entity.Date = DateTime.Now;

                await AddAsync(entity);

                return(SweetAlertExtenstion.Ok());
            }
            catch
            {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #16
0
        public async Task <SweetAlertExtenstion> UpdateInfo(SiteSettingInsertViewModel vm)
        {
            try
            {
                var entity = await Entities.FirstOrDefaultAsync();

                if (vm.LogoFile != null)
                {
                    //حذف فایل قبلی
                    await MFile.Delete(entity.Logo);

                    // ذخیره فایل جدید
                    entity.Logo = await MFile.Save(vm.LogoFile, "Uploads/SiteSetting");
                }

                if (vm.TabIconFile != null)
                {
                    //حذف فایل قبلی
                    await MFile.Delete(entity.TabIcon);

                    // ذخیره فایل جدید
                    entity.TabIcon = await MFile.Save(vm.TabIconFile, "Uploads/SiteSetting");
                }

                entity.InstaURL    = vm.InstaURL;
                entity.WhatsAppURL = vm.WhatsAppURL;
                entity.TwitterURL  = vm.TwitterURL;
                entity.TelegramURL = vm.TelegramURL;

                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e) {
                return(SweetAlertExtenstion.Error());
            }
        }
コード例 #17
0
 async Task <string> UploadPic(IFormFile file)
 => await MFile.Save(file, FilePath.ProductGallery.GetDescription());