public async Task <IActionResult> Base(int id) { var order = await _orderService.SelectAsync(id, true); if (order == null) { return(View(null)); } var token = await _tokenService.CreateTokenAsync(order.Id.ToString(), TimeSpan.FromMinutes(BaseAppConstants.DEFAULT_TOKEN_EXPIRED_MINUTES), TokenType.OrderInvoicePdfAdminGenerateRequest); if (token == null) { return(View(null)); } OrderInvoiceModel model = await _mapper.ToModelAsync <OrderInvoiceModel>(order); string invoicePageUrl = String.Format(BaseAppConstants.ORDER_INVOICE_PAGE_URL_TEMPLATE, _options.Value.AdminHost, token.IdToken.ToString().ToLower()); model.PDFUrl = String.Format(BaseAppConstants.PDF_URL_GENERATE_ORDER_INVOICE_TEMPLATE, _options.Value.PDFMyUrl.ServiceUrl, _options.Value.PDFMyUrl.LicenseKey, WebUtility.UrlEncode(invoicePageUrl), order.Id); return(View(model)); }
public async Task <Result <OrderReviewRuleManageModel> > GetOrderReviewRule(string id) { int idOrderReviewRule = 0; if (id != null && !Int32.TryParse(id, out idOrderReviewRule)) { throw new NotFoundException(); } if (idOrderReviewRule == 0) { return(new OrderReviewRuleManageModel() { StatusCode = RecordStatusCode.Active, ApplyType = ApplyType.All, CompareNamesType = CompareType.Equal, CompareAddressesType = CompareType.Equal, ReshipsRefundsCheckType = OrderType.Reship, ReshipsRefundsMonthCount = 6, }); } var item = await _orderReviewRuleService.SelectAsync(idOrderReviewRule); if (item == null) { throw new NotFoundException(); } OrderReviewRuleManageModel toReturn = await _orderReviewRuleMapper.ToModelAsync <OrderReviewRuleManageModel>(item); return(toReturn); }
public async Task <Result <PagedList <ProductListItemModel> > > GetProducts([FromBody] VProductSkuFilter filter) { var result = await productService.GetProductsAsync2(filter); var agents = await _agentService.GetAgents( result.Items.Where(p => p.IdEditedBy.HasValue).Select(p => p.IdEditedBy.Value).Distinct().ToList()); var toReturn = new PagedList <ProductListItemModel> { Items = await result.Items.Select(async p => { var productItem = await _mapper.ToModelAsync <ProductListItemModel>(p); if (p.IdEditedBy != null) { productItem.EditedByAgentId = agents.GetValueOrDefault(p.IdEditedBy.Value); } return(productItem); }).ToListAsync(), Count = result.Count, }; return(toReturn); }
public async Task <Result <SkuListItemModel> > GetSku([FromBody] VProductSkuFilter filter) { var result = await productService.GetSkusAsync(filter); return (await (result.Select(async p => await _skuMapper.ToModelAsync <SkuListItemModel>(p)).FirstOrDefault() ?? TaskCache <SkuListItemModel> .DefaultCompletedTask)); }
public async Task<Result<AddUpdateCustomerModel>> AddUpdateCustomer( [FromBody] AddUpdateCustomerModel addUpdateCustomerModel) { if (!Validate(addUpdateCustomerModel)) return null; var customer = await _customerMapper.FromModelAsync(addUpdateCustomerModel, (int) CustomerType.Retail); var sUserId = _userManager.GetUserId(User); int userId; if (int.TryParse(sUserId, out userId)) { customer.IdEditedBy = userId; foreach (var address in customer.ShippingAddresses) { address.IdEditedBy = userId; } customer.ProfileAddress.IdEditedBy = userId; } customer.IdEditedBy = userId; if (customer.Id > 0) { customer = await _customerService.UpdateAsync(customer); } else { customer = await _customerService.InsertAsync(customer); if (customer.StatusCode != (int)CustomerStatus.Suspended && !String.IsNullOrEmpty(customer.Email)) { await _storefrontUserService.SendActivationAsync(customer.Id); } } var toReturn = await _customerMapper.ToModelAsync<AddUpdateCustomerModel>(customer); toReturn.IsConfirmed = addUpdateCustomerModel.IsConfirmed; toReturn.PublicUserId = addUpdateCustomerModel.PublicUserId; await PrepareCustomerNotes(customer, toReturn); if (!string.IsNullOrEmpty(toReturn.Email)) { var dbProductReviewEmailEnabled = !await _notificationService.IsEmailUnsubscribedAsync(EmailConstants.ProductReviewIdNewsletter, toReturn.Email); if (addUpdateCustomerModel.ProductReviewEmailEnabled && !dbProductReviewEmailEnabled) { await _notificationService.UpdateUnsubscribeEmailAsync(EmailConstants.ProductReviewIdNewsletter, toReturn.Email, false); } if (!addUpdateCustomerModel.ProductReviewEmailEnabled && dbProductReviewEmailEnabled) { await _notificationService.UpdateUnsubscribeEmailAsync(EmailConstants.ProductReviewIdNewsletter, toReturn.Email, true); } } toReturn.ProductReviewEmailEnabled = addUpdateCustomerModel.ProductReviewEmailEnabled; toReturn.ForReview = (await _customerService.GetCustomersForReviewAsync(new int[] { toReturn.Id })).Any(); return toReturn; }
public async Task <Result <DiscountManageModel> > GetDiscount(string id) { int idProduct = 0; if (id != null && !Int32.TryParse(id, out idProduct)) { throw new NotFoundException(); } if (idProduct == 0) { var now = DateTime.Now; now = new DateTime(now.Year, now.Month, now.Day); return(new DiscountManageModel() { StatusCode = RecordStatusCode.Active, Assigned = CustomerType.Retail, DiscountType = DiscountType.PercentDiscount, StartDate = TimeZoneInfo.ConvertTime(now, TimeZoneHelper.PstTimeZoneInfo, TimeZoneInfo.Local), ExpirationDate = TimeZoneInfo.ConvertTime(now.AddDays(30), TimeZoneHelper.PstTimeZoneInfo, TimeZoneInfo.Local), DiscountsToSelectedSkus = new List <DiscountToSelectedSku>(), DiscountsToSkus = new List <DiscountToSku>(), DiscountTiers = new List <DiscountTier>(), CategoryIds = new List <int>(), CategoryIdsAppliedOnlyTo = new List <int>(), }); } var item = await _discountService.SelectAsync(idProduct); if (item == null) { throw new NotFoundException(); } DiscountManageModel toReturn = await _mapper.ToModelAsync <DiscountManageModel>(item); return(toReturn); }
public async Task <Result <PromotionManageModel> > GetPromotion(string id) { int idPromotion = 0; if (id != null && !Int32.TryParse(id, out idPromotion)) { throw new NotFoundException(); } if (idPromotion == 0) { var now = DateTime.Now; now = new DateTime(now.Year, now.Month, now.Day); return(new PromotionManageModel() { StatusCode = RecordStatusCode.Active, Assigned = CustomerType.Retail, IdObjectType = PromotionType.BuyXGetY, PromotionBuyType = PromoBuyType.Any, StartDate = TimeZoneInfo.ConvertTime(now, TimeZoneHelper.PstTimeZoneInfo, TimeZoneInfo.Local), ExpirationDate = TimeZoneInfo.ConvertTime(now.AddDays(30), TimeZoneHelper.PstTimeZoneInfo, TimeZoneInfo.Local), CanUseWithDiscount = true, PromotionsToBuySkus = new List <PromotionToBuySkuModel>(), PromotionsToGetSkus = new List <PromotionToGetSkuModel>(), }); } var item = await _promotionService.SelectAsync(idPromotion); if (item == null) { throw new NotFoundException(); } PromotionManageModel toReturn = await _mapper.ToModelAsync <PromotionManageModel>(item); return(toReturn); }
//[AdminAuthorize(PermissionType.Customers)] public async Task<Result<AddressModel>> AddAddress([FromBody] AddressModel model, int idCustomer) { if (!Validate(model)) return null; var address = await _addressMapper.FromModelAsync(model); var sUserId = _userManager.GetUserId(User); int userId; if (int.TryParse(sUserId, out userId)) { address.IdEditedBy = userId; } address = await _addressService.InsertAsync(address); var toReturn = await _addressMapper.ToModelAsync<AddressModel>(address); return toReturn; }
//[AdminAuthorize(PermissionType.Customers)] public async Task<Result<CustomerNoteModel>> AddNote([FromBody] CustomerNoteModel model, int idCustomer) { if (!Validate(model)) return null; var note = await _noteMapper.FromModelAsync(model); var sUserId = _userManager.GetUserId(User); int userId; if (int.TryParse(sUserId, out userId)) { note.IdEditedBy = userId; note.IdCustomer = idCustomer; } note = await _notesService.InsertAsync(note); var toReturn = await _noteMapper.ToModelAsync<CustomerNoteModel>(note); return toReturn; }
public async Task <Result <AffiliateManageModel> > GetAffiliate(string id) { int idAffiliate = 0; if (id != null && !Int32.TryParse(id, out idAffiliate)) { throw new NotFoundException(); } if (idAffiliate == 0) { var now = DateTime.Now; now = new DateTime(now.Year, now.Month, now.Day); var defaultCountry = _referenceData.DefaultCountry; return(new AffiliateManageModel() { StatusCode = RecordStatusCode.NotActive, IdCountry = defaultCountry?.Id, PaymentType = AffiliateConstants.DefaultPaymentType, //Credit Tier = AffiliateConstants.DefaultTier, CommissionFirst = AffiliateConstants.DefaultCommissionFirst, CommissionAll = AffiliateConstants.DefaultCommissionAll, }); } var item = await _affiliateService.SelectAsync(idAffiliate); if (item == null) { throw new NotFoundException(); } AffiliateManageModel toReturn = await _mapper.ToModelAsync <AffiliateManageModel>(item); var login = await _affiliateUserService.GetAsync(toReturn.Id); if (login == null) { throw new AppValidationException(ErrorMessagesLibrary.Data[ErrorMessagesLibrary.Keys.CantFindLogin]); } toReturn.IsConfirmed = login.IsConfirmed; toReturn.PublicUserId = login.PublicId; CountryFilter filter = new CountryFilter(); var countries = await _countryService.GetCountriesAsync(filter); var country = countries.FirstOrDefault(p => p.Id == toReturn.IdCountry); if (country != null) { toReturn.CountryCode = country.CountryCode; var state = country.States.FirstOrDefault(p => p.Id == toReturn.IdState); if (state != null) { toReturn.StateCode = state.StateCode; } } return(toReturn); }