Beispiel #1
0
        public async Task <IActionResult> Update(ProductPackageUpdateViewModel package
                                                 , PackageFeatureInsertViewModel vm
                                                 , List <int> groups
                                                 , IFormFile file)
        {
            if (_productPackageGroupRepository.IsGroupChanged(package.Id, groups))
            {
                await _productPackageDetailsRepostitory.RemoveProductsbyPackageId(package.Id);
            }

            // ویرایش پکیج
            var productId = await _productPackageRepostitory.UpdateAsync(package, file);

            await _productPackageGroupRepository.AddGroupRange(groups, package.Id);

            if (vm.Items != null || vm.Items.Count > 0)
            {
                await _packageUserAnswerRepository.UpdateAnswer(vm, UserId, package.Id);
            }

            TempData.AddResult(SweetAlertExtenstion.Ok());

            // بازگشت به لیست محصولات
            return(Redirect(IndexUrlWithQueryString));
        }
Beispiel #2
0
        public async Task <SweetAlertExtenstion> UpdateAnswer(PackageFeatureInsertViewModel vm
                                                              , int userId, int packageId)
        {
            var model = await GetListAsync(a => a.PackageId == packageId);

            await DeleteRangeAsync(model.ToList());

            return(await AddAnswer(vm, userId, packageId));
        }
Beispiel #3
0
        public async Task <IActionResult> Create(ProductPackageInsertViewModel product
                                                 , PackageFeatureInsertViewModel vm
                                                 , List <int> groups
                                                 , IFormFile file)
        {
            // ثبت پکیج
            var packageId = await _productPackageRepostitory.CreateAsync(product, file);

            await _packageUserAnswerRepository.AddAnswer(vm, UserId, packageId);

            await _productPackageGroupRepository.AddGroupRange(groups, packageId);

            // نمایش پیغام
            TempData.AddResult(SweetAlertExtenstion.Ok());

            // بازگشت به لیست محصولات
            return(Redirect(IndexUrlWithQueryString));
        }
Beispiel #4
0
        public async Task <SweetAlertExtenstion> AddAnswer(PackageFeatureInsertViewModel vm
                                                           , int userId, int packageId)
        {
            var list = new List <PackageUserAnswers>();

            foreach (var item in vm.Items)
            {
                list.Add(new PackageUserAnswers()
                {
                    Answer     = item.FeatureValue.ToString(),
                    QuestionId = item.QuestionId,
                    IsManager  = true,
                    PackageId  = packageId,
                    UserId     = userId,
                    FeatureId  = item.FeatureId
                });
            }

            await AddRangeAsync(list, false);

            return(await SaveAsync());
        }