public async Task <ActionResult> SetIndexSections(IndexSectionsModel ism)
        {
            try
            {
                IndexBoxInfoModel BoxInfo = ((List <IndexBoxInfoModel>)(await _indexboxinforepo.GetAll()).Data).FirstOrDefault(x => x.I_SecId == ism.Section && x.Lang == ism.Lang);

                if (BoxInfo == null)
                {
                    await _indexboxinforepo.Insert(new IndexBoxInfoModel()
                    {
                        I_SecId = ism.Section,
                        I_Title = ism.Title,
                        I_Icon  = ism.Icon,
                        I_Sort  = ism.Sort,
                        Lang    = ism.Lang
                    });

                    await _indexboxinforepo.CommitAllChanges();
                }
                else
                {
                    await _indexboxinforepo.Update(new IndexBoxInfoModel()
                    {
                        I_Id    = BoxInfo.I_Id,
                        I_SecId = ism.Section,
                        I_Title = ism.Title,
                        I_Icon  = ism.Icon,
                        I_Sort  = ism.Sort,
                        Lang    = ism.Lang
                    });

                    await _indexboxinforepo.CommitAllChanges();
                }
                List <IndexBoxProductRelModel> OldRelations = ((List <IndexBoxProductRelModel>)(await _indexsectionrepo.GetAll()).Data).Where(x => x.I_SecId == ism.Section && x.Lang == ism.Lang).ToList();
                foreach (var item in OldRelations)
                {
                    await _indexsectionrepo.Delete(item);
                }
                await _indexsectionrepo.CommitAllChanges();

                foreach (int p in ism.Products)
                {
                    await _indexsectionrepo.Insert(new IndexBoxProductRelModel()
                    {
                        Lang    = ism.Lang,
                        I_Pid   = p,
                        I_SecId = ism.Section
                    });
                }
                await _indexsectionrepo.CommitAllChanges();

                return(new JsonResult(ResponseModel.Success("اطلاعات با موفقیت ذخیره گردید")));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public async Task <ActionResult> DeleteService(ServiceModel service)
 {
     try
     {
         return(new JsonResult(await _servicerepo.Delete(service.S_Id)));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Пример #3
0
        public async Task <ResponseStructure> TestCheckout(HttpRequest httpRequest, HttpResponse httpResponse, int type = 1, bool RequestedPOS = false)
        {
            try
            {
                var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(httpRequest);
                if (authorize < 1)
                {
                    return(ResponseModel.Error("کاربر وارد نشده است"));
                }
                UserModel userModel = await _userrepository.GetById(authorize);

                if (userModel == null)
                {
                    return(ResponseModel.Error("کاربر یافت نشد"));
                }
                FullPropertyBasketModel BasketModel = new FullPropertyBasketModel();
                string cookie;
                string InvoiceID = null;
                if (httpRequest.Cookies.TryGetValue("Cart", out cookie))
                {
                    if (cookie != null)
                    {
                        var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie);
                        BasketModel = JsonConvert.DeserializeObject <FullPropertyBasketModel>(basketInfo);
                        if (BasketModel.CartItems.Count() > 0)
                        {
                            BasketViewModel basketView = await GetBasketItems(httpRequest);

                            InvoiceModel Invoice = new InvoiceModel();
                            Invoice.I_BoxWrapperId       = BasketModel.GiftBoxWrapperId;
                            Invoice.I_CopponDiscount     = (BasketModel.Coppon.Count() > 0) ? BasketModel.Coppon.Sum(x => x.CP_Discount) : 0;
                            Invoice.I_CopponId           = (BasketModel.Coppon.Count() > 0) ? BasketModel.Coppon.FirstOrDefault().CP_Id : 0;
                            Invoice.I_DeliveryDate       = BasketModel.RecipientInfo.DeliveryDate;
                            Invoice.I_PaymentDate        = DateTime.Now;
                            Invoice.I_PaymentInfo        = "Test payment";
                            Invoice.I_PaymentType        = type;
                            Invoice.I_RecipientInfo      = JsonConvert.SerializeObject(BasketModel.RecipientInfo);
                            Invoice.I_RequestedPOS       = RequestedPOS;
                            Invoice.I_Status             = 2;
                            Invoice.I_TotalProductAmount = basketView.Products.Sum(x => x.Total);
                            Invoice.I_TotalAmount        = basketView.Total;
                            Invoice.I_UserId             = userModel.U_Id;
                            Invoice.I_Id = UtilesService.RandomDigit(12);
                            var insertInvoiceResult = await _invoicerepository.Insert(Invoice);

                            if (insertInvoiceResult.Status == false)
                            {
                                return(insertInvoiceResult);
                            }
                            int AvailAbleCounts = 0;
                            foreach (var item in BasketModel.CartItems)
                            {
                                OrderModel order = new OrderModel();
                                if (item.ProductType == 1)
                                {
                                    var combine = await _productcombinerepo.GetById(item.ProductCombineId);

                                    if (combine != null && combine.X_AvailableCount >= item.Quantity)
                                    {
                                        AvailAbleCounts++;
                                        order.O_ColorId      = combine.X_ColorId;
                                        order.O_ProductId    = combine.X_ProductId;
                                        order.O_WarrantyId   = combine.X_WarrantyId;
                                        order.O_ReciptId     = Invoice.I_Id;
                                        order.O_Quantity     = item.Quantity;
                                        order.O_ProductType  = 1;
                                        order.O_Price        = combine.PriceModel.Price;
                                        order.O_Discount     = combine.PriceModel.HasDiscount ? combine.PriceModel.Discount : 0;
                                        order.O_DiscountType = 1;
                                        order.O_GiftId       = item.GiftProductCombineId;
                                        await _orderrepository.Insert(order);
                                    }
                                }
                                else
                                {
                                    var pmanual = await _productmanualrepo.GetById(item.ProductCombineId);

                                    if (pmanual != null)
                                    {
                                        AvailAbleCounts++;
                                        order.O_ProductId   = pmanual.M_ProductId;
                                        order.O_ReciptId    = Invoice.I_Id;
                                        order.O_Quantity    = item.Quantity;
                                        order.O_ProductType = 2;
                                        order.O_Price       = pmanual.M_Price;
                                        await _orderrepository.Insert(order);
                                    }
                                }
                            }
                            InvoiceID = Invoice.I_Id;
                            if (AvailAbleCounts < 1)
                            {
                                await _invoicerepository.Delete(InvoiceID);
                                await FreeUpCart(httpRequest, httpResponse);

                                return(ResponseModel.Error("تمامی کالاهای موجود در سبد خرید شما ناموجود میباشند"));
                            }
                        }
                    }
                }

                await FreeUpCart(httpRequest, httpResponse);

                return(ResponseModel.Success("سفارش شما با موفقیت ثبت گردید", data: InvoiceID));
            }
            catch (Exception ex)
            {
                return(ResponseModel.ServerInternalError(data: ex));
            }
        }