public async Task <object> TodayIncome() { try { DateTime today = DateTime.Now; var allInvoices = _context.Invoice.Where(x => ((DateTime)x.Created_At).Day == today.Day).ToList(); decimal Total = allInvoices.Sum(x => x.I_TotalAmount); decimal yesterdayIncome = await this.TodayIncome(today.AddDays(-1)); if (yesterdayIncome == 0) { yesterdayIncome = 0.1M; } var perc = this.PercentChangeBetweenTwoNumber(yesterdayIncome, Total); if (perc > 1000) { perc = 1000; } return(ResponseModel.Success(data: new { change = perc, income = (Total != 0) ? Total.ToString("#,#") : "0", value = new decimal[] { yesterdayIncome, Total } })); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> FreeUpCart(HttpRequest httpRequest, HttpResponse httpResponse) { try { StringValues data; FullPropertyBasketModel basket = new FullPropertyBasketModel(); string cookie; if (httpRequest.Cookies.TryGetValue("Cart", out cookie)) { if (cookie != null) { httpResponse.Cookies.Delete("Cart"); string token = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(JsonConvert.SerializeObject(basket)); httpResponse.Cookies.Append("Cart", token); } } return(ResponseModel.Success("Cart free.")); } catch (Exception ex) { _logger.LogError("Error in free up basket cart", ex); return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <object> LastOrders() { try { List <object> Items = new List <object>(); var LastOrders = _context.Invoice.OrderByDescending(x => x.ID).Take(10).ToList(); Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fa-IR"); foreach (var invoice in LastOrders) { var user = _context.Users.FirstOrDefault(x => x.U_Id == invoice.I_UserId); string userInfo = user != null ? user.U_Name + " " + user.U_Family : "ناشناس"; object item = new { orderNumber = invoice.I_Id, orderDate = (((DateTime)invoice.Created_At).ToString("yyyy/MM/dd ساعت HH:mm:ss")), orderCustomer = userInfo, orderSum = invoice.I_TotalAmount.ToString("#,#"), orderState = invoice.I_Status }; Items.Add(item); } return(ResponseModel.Success(data: Items)); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <object> SaleByCategories() { try { var LastOrders = _context.Order.ToList(); var AllCategories = _context.ProductCategory.Where(x => x.PC_ParentId == 0 && x.PC_IsDeleted != true && x.PC_Status).ToList(); int CountOrders = LastOrders.Sum(x => x.O_Quantity); Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fa-IR"); List <object> Labels = new List <object>(); List <object> Series = new List <object>(); foreach (var category in AllCategories) { var products = _context.Product.Where(x => x.P_MainCatId == category.PC_Id).ToList(); int count = 0; foreach (var product in products) { var order = LastOrders.Where(x => x.O_ProductId == product.P_Id).ToList(); int quantity = order.Sum(x => x.O_Quantity); count += quantity; } Labels.Add(category.PC_Title); Series.Add(count); } return(ResponseModel.Success(data: new { labels = Labels, series = Series })); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ActionResult> ReduceWallet(UserModel um) { try { var user = await _userrepo.GetById(um.U_Id); if (user == null) { return(new JsonResult(ResponseModel.Error("کاربر یافت نشد"))); } var doTransaction = await _walletrepo.DecreaseWallet(user.U_Id, um.U_Wallet); if (doTransaction.Status) { if (user.U_Phone != null && user.U_Phone != "") { await _smsService.WalletAllert(user.U_Phone, 2, um.U_Wallet.ToString("#,#")); } return(new JsonResult(ResponseModel.Success("عملیات با موفقیت انجام گردید"))); } else { return(new JsonResult(doTransaction)); } } catch (Exception ex) { _logger.LogError("Erro in user controller", ex); return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ActionResult> LoadUserWalletHistory(UserModel um) { try { var allHistories = (List <WalletHistoryModel>)(await _walletrepo.GetAll()).Data; allHistories = allHistories.Where(x => x.WH_CustomerId == um.U_Id).ToList(); List <object> result = new List <object>(); int i = 1; foreach (var item in allHistories) { result.Add(new { counter = i, amount = item.WH_Amount, type = item.WH_TransactionType == 1 ? "واریز" : "برداشت", user = item.WH_AdderId == 0 ? "مدیر سیستم" : "کاربر", date = ((DateTime)item.Created_At).ToString("yyyy/MM/dd HH:mm:ss") }); i++; } return(new JsonResult(ResponseModel.Success("Wallet history returned", result))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ResponseStructure> Insert(ProductManualModel entity) { try { var exists = _context.ProductManual.FirstOrDefault(x => x.M_ProductId == entity.M_ProductId); if (exists != null) { exists.M_FileName = entity.M_FileName; exists.M_Status = entity.M_Status; exists.M_Title = entity.M_Title; exists.M_Price = entity.M_Price; exists.Updated_At = DateTime.Now; this._context.ProductManual.Update(entity: entity); await this.CommitAllChanges(); return(ResponseModel.Success()); } entity.Created_At = DateTime.Now; entity.Updated_At = DateTime.Now; await this._context.ProductManual.AddAsync(entity : entity); await this.CommitAllChanges(); return(ResponseModel.Success()); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ActionResult> Login(UserModel um) { try { um.U_Role = 1; var login = await _userrepo.AdminLogin(um); if (!login.Status) { return(new JsonResult(login)); } var token = ((UserModel)login.Data).Token; Response.Cookies.Append("BarayandCPUser", token); return(new JsonResult(ResponseModel.Success("Login successfull.", new { un = ((UserModel)login.Data).U_Name, uln = ((UserModel)login.Data).U_Family, ue = ((UserModel)login.Data).U_Email, up = ((UserModel)login.Data).U_Phone, ua = ((UserModel)login.Data).U_Avatar, uid = ((UserModel)login.Data).U_Id, perms = ((UserModel)login.Data).Permissions }))); } catch (Exception ex) { _logger.LogError("Error in user login", ex); return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ResponseStructure> Insert(PromotionBoxModel entity) { try { var checkExists = await GetBySectionId(entity.B_SectionId); if (checkExists != null) { checkExists.B_LoadType = entity.B_LoadType; checkExists.B_Link = entity.B_Link; checkExists.B_Image = entity.B_Image; checkExists.B_Seo = entity.B_Seo; checkExists.B_Title = entity.B_Title; checkExists.B_Type = entity.B_Type; checkExists.B_ColorCode = entity.B_ColorCode; checkExists.B_EntityId = entity.B_EntityId; checkExists.Updated_At = DateTime.Now; return(await this.Update(checkExists)); } else { this._context.PromotionBoxs.Add(entity); await this._context.SaveChangesAsync(); return(ResponseModel.Success("باکس مورد نظر با موفقیت بروزرسانی گردید")); } } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ActionResult> LoadOffRequests() { try { var AllReqs = (List <OfflinRequestModel>)(await _offreqrepo.GetAll()).Data; List <object> result = new List <object>(); Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fa"); int i = 1; foreach (var item in AllReqs.OrderByDescending(x => (DateTime)x.Created_At)) { var user = await _userrepo.GetById(item.O_User); result.Add(new { id = item.O_Id, counter = i, user = (user != null) ? user.U_Name + " " + user.U_Family : "", url = item.O_Url, detail = item.O_Details, price = item.O_Price, deliver = item.O_DeliverDate, reqdate = ((DateTime)item.Created_At).ToString("yyyy/MM/dd HH:mm:ss"), reason = item.O_Reason, status = item.O_Status }); i++; } return(new JsonResult(ResponseModel.Success(data: result))); } catch (Exception ex) { _logger.LogError("Error", ex); return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ActionResult> GetAllAttrsByCat(int catid) { try { CatAttrRelationRepository carr = new CatAttrRelationRepository(new DAL.Context.BarayandContext(null)); var catattrs = ((List <CatAttrRelationModel>)(await _repository.GetAll()).Data).Where(x => x.X_IsDeleted == false && x.X_Status && x.X_CatId == catid).ToList(); List <AttributeModel> data = ((List <AttributeModel>)(await _attrs.GetAll()).Data); List <object> Data = new List <object>(); foreach (var item in catattrs) { var attribute = data.FirstOrDefault(x => x.A_Id == item.X_AttrId); if (attribute != null) { Data.Add(new { A_Title = attribute.A_Title, A_Id = attribute.A_Id, A_Status = item.X_Status, relationId = item.X_Id, }); } } return(new JsonResult(ResponseModel.Success(data: Data))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ResponseStructure> Update(ProductCombineModel entity) { try { var all = ((List <ProductCombineModel>)(await this.GetAll()).Data); if (all.Count(x => x.X_Id != entity.X_Id && x.X_ProductId == entity.X_ProductId && x.X_WarrantyId == entity.X_WarrantyId && x.X_ColorId == entity.X_ColorId && !x.X_IsDeleted) > 0) { return(ResponseModel.Error("ترکیب آماری مورد نظر برای گارانتی و رنگ انتخابی قبلا تعریف شده است")); } if (entity.X_Default) { var allCombines = all.Where(x => x.X_ProductId == entity.X_ProductId).ToList(); foreach (var cmb in allCombines) { cmb.X_Default = false; } _context.ProductCombine.UpdateRange(allCombines); await this.CommitAllChanges(); } var item = await this.GetById(entity.X_Id); entity.Created_At = item.Created_At; entity.Updated_At = DateTime.Now; this._context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Detached; this._context.ProductCombine.Update(entity); await this._context.SaveChangesAsync(); return(ResponseModel.Success("رکورد مورد نظر با موفقیت بروزرسانی گردید")); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> Insert(ProductCombineModel entity) { try { var all = ((List <ProductCombineModel>)(await this.GetAll()).Data); if (all.Count(x => x.X_ProductId == entity.X_ProductId && x.X_WarrantyId == entity.X_WarrantyId && x.X_ColorId == entity.X_ColorId && !x.X_IsDeleted) > 0) { return(ResponseModel.Error("ترکیب آماری مورد نظر برای گارانتی و رنگ انتخابی قبلا تعریف شده است")); } if (entity.X_Default) { var allCombines = all.Where(x => x.X_ProductId == entity.X_ProductId).ToList(); foreach (var cmb in allCombines) { cmb.X_Default = false; } _context.ProductCombine.UpdateRange(allCombines); await this.CommitAllChanges(); } await this.DbSet.AddAsync(entity : entity); await this.CommitAllChanges(); return(ResponseModel.Success("ترکیب آماری با موفقیت ایجاد گردید")); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> UpdateRelation(List <PromotionBoxProductsModel> data) { try { if (data == null || data.Count() < 1) { return(ResponseModel.Error("Relation not found")); } var rel = this._context.PromotionBoxProducts.ToList(); foreach (var item in data) { var existsInOtherBoxs = rel.FirstOrDefault(x => x.X_WarrantyId == item.X_WarrantyId && x.X_ColorId == item.X_ColorId && x.X_SectionId != item.X_SectionId && item.X_ProdId == item.X_ProdId); if (existsInOtherBoxs != null) { data.Remove(item); } } this._context.PromotionBoxProducts.RemoveRange(rel.Where(x => x.X_SectionId == data.FirstOrDefault().X_SectionId).ToList()); await this.CommitAllChanges(); await this._context.PromotionBoxProducts.AddRangeAsync(data); await this.CommitAllChanges(); return(ResponseModel.Success("عملیات با موفقیت انجام گردید")); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> SaveReciptientInfo(HttpRequest httpRequest, HttpResponse httpResponse) { try { StringValues data; if (!httpRequest.Headers.TryGetValue("ReciptientInfo", out data)) { return(ResponseModel.Error("Invalid access detect.")); } var dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data); ReciptientInfoModel rm = JsonConvert.DeserializeObject <ReciptientInfoModel>(dec); FullPropertyBasketModel basket = new FullPropertyBasketModel(); string cookie; if (httpRequest.Cookies.TryGetValue("Cart", out cookie)) { if (cookie != null) { var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie); basket = JsonConvert.DeserializeObject <FullPropertyBasketModel>(basketInfo); basket.RecipientInfo = rm; } } string token = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(JsonConvert.SerializeObject(basket)); httpResponse.Cookies.Delete("Cart"); httpResponse.Cookies.Append("Cart", token); return(ResponseModel.Success("اطلاعات دریافت کننده سفارش با موفقیت ذخیره گردید.")); } catch (Exception ex) { _logger.LogError("Error in adding reciver info to customer basket", ex); return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> Send() { try { this.Url += string.Format("&pid={0}&tnum={1}", this.PatternId, this.To); var client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(this.Url); HttpContent responseContent = response.Content; using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync())) { var resp = await reader.ReadToEndAsync(); if (resp == "0") { return(ResponseModel.Error("Error in sending sms.", resp)); } } return(ResponseModel.Success()); } catch (Exception ex) { _logger.LogError("Error in Send Method SMSCLASS", ex); return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> UpdateRelation(List <GiftProductModel> data, int prodid) { try { if (data.Count() > 1) { return(ResponseModel.Error("به هر محصول فقط میتوان یک هدیه نسبت داد")); } var rel = this._context.GiftProduct.ToList(); this._context.GiftProduct.RemoveRange(rel.Where(x => x.X_MainProdId == prodid).ToList()); await this.CommitAllChanges(); if (data == null || data.Count() == 1) { await this._context.GiftProduct.AddRangeAsync(data); await this.CommitAllChanges(); } return(ResponseModel.Success("عملیات با موفقیت انجام گردید")); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> RechargeWallet(int user, decimal amount, string recieptInfo = "") { try { UserModel userModel = this._context.Users.FirstOrDefault(x => x.U_Id == user); if (amount == 0) { return(ResponseModel.Error("Cannot increase zero amount")); } userModel.U_Wallet = userModel.U_Wallet + amount; this._context.Users.Update(userModel); await this._context.SaveChangesAsync(); await this.LogTransaction(new WalletHistoryModel() { WH_AdderId = 0, WH_CustomerId = user, WH_Amount = amount, WH_TransactionType = 1, WH_PayType = 0, WH_PayBankRecip = recieptInfo }); return(ResponseModel.Success("Transaction completed successfully.")); } catch (Exception ex) { return(ResponseModel.ServerInternalError("Server Internal Error", ex)); } }
public async Task <IActionResult> CompareSerch(string title, int cat2, int?brand) { try { if (cat2 > 0) { var getAllProductByCatId = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_EndLevelCatId == cat2).ToList(); if (!string.IsNullOrEmpty(title)) { getAllProductByCatId = getAllProductByCatId.Where(x => x.P_Title.Contains(title, StringComparison.InvariantCultureIgnoreCase)).ToList(); } if (brand != null && brand > 0) { getAllProductByCatId = getAllProductByCatId.Where(x => x.P_BrandId == brand).ToList(); } var model = await _viewRenderer.RenderAsync(this, "_productlist", getAllProductByCatId); return(new JsonResult(ResponseModel.Success(data: model))); } return(new JsonResult(ResponseModel.ServerInternalError(data: "error"))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ResponseStructure> DecreaseWallet(int user, decimal amount) { try { UserModel userModel = this._context.Users.FirstOrDefault(x => x.U_Id == user); if (userModel.U_Wallet < amount) { return(ResponseModel.Error("Account balance is not enough")); } userModel.U_Wallet = userModel.U_Wallet - amount; this._context.Users.Update(userModel); await this._context.SaveChangesAsync(); await this.LogTransaction(new WalletHistoryModel() { WH_AdderId = 0, WH_CustomerId = user, WH_Amount = amount, WH_TransactionType = 2, WH_PayType = 0, WH_PayBankRecip = "" }); return(ResponseModel.Success("Transaction completed successfully.")); } catch (Exception ex) { return(ResponseModel.ServerInternalError("Server Internal Error", ex)); } }
public async Task <ResponseStructure> AdminLogin(UserModel um) { try { var getAll = (List <UserModel>)(await GetAll()).Data; var exists = getAll.FirstOrDefault(x => x.U_Email == um.U_Email); bool truepwd = false; if (exists == null || !CryptoJsService.verifyPassword(exists.U_Password, um.U_Password)) { return(ResponseModel.Error("Sorry,we couldn't find an account with that username and password.")); } if (exists.U_Status == 2) { return(ResponseModel.Error("Your account has been suspened.")); } if (um.U_Role == 1) { var perms = _context.Permissions.Where(x => x.Perm_Uid == exists.U_Id).ToList(); foreach (var perm in perms) { um.Permissions.Add(perm.Perm_Urlid); } } var token = TokenService.GenerateToken(exists.U_Id, exists.U_Name + " " + exists.U_Family, exists.U_Email); um.Token = token; return(ResponseModel.Success(data: um)); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> UpdatePassword(HttpRequest httpRequest, Microsoft.AspNetCore.Http.HttpResponse response, int userId) { try { UserModel userModel = await this.GetById(userId); if (userModel == null) { return(ResponseModel.Error("Your login token has expired.", new { EXPIREDTOKEN = true })); } var data = httpRequest.Headers["PasswordUpdate"]; var dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data); RegisterModel rm = JsonConvert.DeserializeObject <RegisterModel>(dec); if (!Barayand.Common.Services.CryptoJsService.verifyPassword(userModel.U_Password, rm.CurrentPassword)) { return(ResponseModel.Error("Current password was incorrect.")); } if (rm.ConfirmPassword != rm.Password) { return(ResponseModel.Error("Password and confirm password does not match.")); } userModel.U_Password = Barayand.Common.Services.CryptoJsService.HashPassword(rm.Password); response.Cookies.Delete("ValhallaUser"); return(await this.Update(userModel)); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> UpdateProfile(HttpRequest httpRequest, int userId) { try { UserModel userModel = await this.GetById(userId); if (userModel == null) { return(ResponseModel.Error("Your login token has expired.", new { EXPIREDTOKEN = true })); } var data = httpRequest.Headers["UpdateData"]; var dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data); RegisterModel rm = JsonConvert.DeserializeObject <RegisterModel>(dec); userModel.U_Avatar = rm.Avatar; userModel.U_Family = rm.Family; userModel.U_Name = rm.Name; userModel.U_Phone = rm.Phone; userModel.U_HomeTel = rm.HomeTel; userModel.U_IdentityCode = rm.IdentityCode; userModel.U_CreditCardNum = rm.CreditCardNum; userModel.U_BirthDate = rm.BirthDate; userModel.U_Email = rm.Email; return(await this.Update(userModel)); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <IActionResult> AddToCompare(int id) { try { string cookie = ""; var prod = await _productrepo.GetById(id); if (prod == null) { return(new JsonResult(ResponseModel.Error("محصول یافت نشد"))); } if (HttpContext.Request.Cookies.TryGetValue("Compaire", out cookie)) { if (cookie != null) { var decryptCookie = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie); CompareCookieModel ccm = JsonConvert.DeserializeObject <CompareCookieModel>(decryptCookie); if (ccm.Products.Count() > 0) { if (ccm.Products.Count(x => x == prod.P_Id) > 0) { return(new JsonResult(ResponseModel.Error("محصول مورد نظر قبلا در لیست مقایسه ثبت شده است"))); } var p = await _productrepo.GetById(ccm.Products.FirstOrDefault()); if (p != null) { if (p.P_EndLevelCatId != prod.P_EndLevelCatId) { return(new JsonResult(ResponseModel.Error("فقط محصولاتی میتوانند در لیست دسته بندی قرار گیرند که در یک گروه قرار داشته باشند"))); } } ccm.Products.Add(prod.P_Id); } else { ccm.Products.Add(prod.P_Id); } var SerilizedCcm = JsonConvert.SerializeObject(ccm); var encryptData = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(SerilizedCcm); Response.Cookies.Append("Compaire", encryptData); } return(new JsonResult(ResponseModel.Success("محصول مورد نظر با موفقیت به لیست مقایسه اضافه گردید"))); } else { CompareCookieModel ccm = new CompareCookieModel(); ccm.Products.Add(prod.P_Id); var SerilizedCcm = JsonConvert.SerializeObject(ccm); var encryptData = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(SerilizedCcm); Response.Cookies.Append("Compaire", encryptData); return(new JsonResult(ResponseModel.Success("محصول مورد نظر با موفقیت به لیست مقایسه اضافه گردید"))); } } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <ResponseStructure> DecreaseProductCount(HttpRequest httpRequest, HttpResponse httpResponse) { try { if (!this.STOREISACTIVE) { return(ResponseModel.Error("با عرض پوزش ، در حال حاضر امکان سفارش گیری وجود ندارد")); } StringValues data; if (!httpRequest.Headers.TryGetValue("AddToCart", out data)) { return(ResponseModel.Error("دسترسی غیر مجاز")); } var dec = Barayand.Common.Services.CryptoJsService.DecryptStringAES(data); FullPropertyBasketItem rm = JsonConvert.DeserializeObject <FullPropertyBasketItem>(dec); ProductCombineModel findProduct = new ProductCombineModel(); FullPropertyBasketModel BasketModel = new FullPropertyBasketModel(); string cookie; 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) { if (BasketModel.CartItems.Count(x => x.ProductCombineId == rm.ProductCombineId && x.ProductType == rm.ProductType) > 0) { var existsCombine = BasketModel.CartItems.FirstOrDefault(x => x.ProductCombineId == rm.ProductCombineId && x.ProductType == rm.ProductType); existsCombine.Quantity = existsCombine.Quantity - rm.Quantity; if (existsCombine.Quantity < 1) { BasketModel.CartItems.Remove(existsCombine); } } } } } string token = Barayand.Common.Services.CryptoJsService.EncryptStringToAES(JsonConvert.SerializeObject(BasketModel)); httpResponse.Cookies.Delete("Cart"); httpResponse.Cookies.Append("Cart", token); return(ResponseModel.Success("محصول مورد نظر با موفقیت به سبد خرید اضافه گردید")); } catch (Exception ex) { _logger.LogError("Error in adding product to basket", ex); return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ActionResult> GetProductionCategoryAttributes(Miscellaneous misc) { try { if (misc.Id == 0) { return(new JsonResult(ResponseModel.Error(msg: "دسته بندی یافت نشد"))); } var getChilds = (List <ProductCategoryModel>)(await this._repository.GetAllByParentIdOneLevel(misc.Id)).Data; var AllAttributes = ((List <AttributeModel>)(await this._attrrepository.GetAll()).Data).Where(x => !x.A_IsDeleted && x.A_Status).ToList(); var AllCatAttributes = (List <CatAttrRelationModel>)(await this._catattrrepository.GetAll()).Data; var AllAnswers = ((List <AttrAnswerModel>)(await this._attranswerrepository.GetAll()).Data).Where(x => !x.X_IsDeleted && x.X_Status).ToList(); List <SetAttributeComboModel> Attributes = new List <SetAttributeComboModel>(); var catattr = AllCatAttributes.Where(x => x.X_CatId == misc.Id); foreach (var item in catattr) { string ATitle = ""; int AId = 0; int AType = 0; List <object> AnswersList = new List <object>(); var attribute = AllAttributes.FirstOrDefault(x => x.A_Id == item.X_AttrId); if (attribute != null) { ATitle = attribute.A_Title; AId = attribute.A_Id; AType = attribute.A_Type; if (AType == 1) { var answers = AllAnswers.Where(x => x.X_CatAttrId == item.X_Id); foreach (var ansItem in answers) { AnswersList.Add(new { Id = ansItem.X_Id, Title = ansItem.X_Answer }); } } Attributes.Add(new SetAttributeComboModel() { Answer = AnswersList, Id = AId, Title = ATitle, Type = AType }); } else { continue; } } return(new JsonResult(ResponseModel.Success(data: Attributes))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <IActionResult> Add() { try { return(new JsonResult(await _basketservice.AddToCart(Request, Response))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError())); } }
public async Task <IActionResult> TestCheckout(int type = 1) { try { return(new JsonResult(await _basketservice.TestCheckout(Request, Response, type))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError())); } }
public async Task <IActionResult> SaveReciptientInfo() { try { return(new JsonResult(await _basketservice.SaveReciptientInfo(Request, Response))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError())); } }
public async Task <ActionResult> GetProductAttr(int pid) { try { return(new JsonResult(ResponseModel.Success(msg: "PRODUCT_ATTRIBUTE_ANSWER_RETURNED", data: await this._productAttrAnswerrepo.GetProductAttributes(pid)))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }