public async Task <IActionResult> All(int productId, int selectedPage, int maxItemsPerPage) { try { int totalCount = await _DbContext.Comments.CountAsync() .ConfigureAwait(false); List <Comment> list = await _DbContext.Comments.Include(c => c.Product).Include(c => c.User) .Where(c => c.Product.Id == productId) .OrderBy(c => c.Date) .Skip((selectedPage - 1) * maxItemsPerPage) .Take(maxItemsPerPage) .ToListAsync() .ConfigureAwait(false); return(Ok(new MultiResult <List <Comment>, int>(list, totalCount, CoreFunc.GetCustomAttributeTypedArgument(ControllerContext)))); } catch (Exception ex) { /// in the case any exceptions return the following error CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> SalesStatistics(SalesPeriod salePeriod) { try { MultiResult <List <string>, List <decimal>, List <int> > result = new MultiResult <List <string>, List <decimal>, List <int> >(); switch (salePeriod) { case SalesPeriod.Daily: result = await GetDaily(CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)); break; case SalesPeriod.Monthly: result = await GetMonthly(CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)); break; case SalesPeriod.Yearly: result = await GetYearly(CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)); break; default: break; } ; return(Ok(result)); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
[Authorize(AppConst.AccessPolicies.Secret)] /// Ready for test public async Task <IActionResult> Search( int selectedPage, int maxNumberPerItemsPage, string searchValue = "", string filterType = CoreConst.GetAllRecords, bool isSortAsce = true, string sortName = "Code") { try { int totalCount = await _DbContext.Coupons .Where(r => filterType.Equals(CoreConst.GetAllRecords)? true : r.Type.Equals((CouponType)Enum.Parse(typeof(CouponType), filterType, true))) .CountAsync(c => searchValue.Equals(CoreConst.GetAllRecords) ? true : c.Code.Contains(searchValue)) .ConfigureAwait(false); List <Coupon> list = await _DbContext.Coupons .Where(r => filterType.Equals(CoreConst.GetAllRecords)?true : r.Type.Equals((CouponType)Enum.Parse(typeof(CouponType), filterType, true))) .OrderByDynamic(sortName, isSortAsce) .Where(c => searchValue.Equals(CoreConst.GetAllRecords) ? true : c.Code.Contains(searchValue)) .Skip((selectedPage - 1) * maxNumberPerItemsPage) .Take(maxNumberPerItemsPage) .ToListAsync() .ConfigureAwait(false); return(Ok(new MultiResult <List <Coupon>, int>(list, totalCount, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> Search( int selectedPage, int maxNumberPerItemsPage, string searchValue = "", bool isSortAsce = true, string sortName = "Name") { try { int totalCount = await _DbContext.Categories .CountAsync(c => searchValue.Equals(CoreConst.GetAllRecords)?true : c.Name.Contains(searchValue)) .ConfigureAwait(false); List <Category> list = await _DbContext.Categories .Where(c => searchValue.Equals(CoreConst.GetAllRecords)?true : c.Name.Contains(searchValue)) .OrderByDynamic(sortName, isSortAsce) .Skip((selectedPage - 1) * maxNumberPerItemsPage) .Take(maxNumberPerItemsPage) .ToListAsync() .ConfigureAwait(false); foreach (var category in list) { category.TotalProducts = await _DbContext.Products .CountAsync(p => p.Category.Id == category.Id) .ConfigureAwait(false); } return(Ok(new MultiResult <List <Category>, int>(list, totalCount, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> Get( int selectedPage = 1, int maxItemsPerPage = 5, string searchValue = CoreConst.GetAllRecords, string filterRole = CoreConst.GetAllRecords, bool isSortAsce = true, string sortName = "Name" ) { try { _ = int.TryParse(filterRole, out int filterRoleId); int totalCount = await _DbContext.Users .Include(u => u.Role) .Where(u => filterRole.Equals(CoreConst.GetAllRecords) || u.Role.Id == filterRoleId) .CountAsync(u => searchValue.Equals(CoreConst.GetAllRecords) || (u.FirstName.Contains(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.Surname.Contains(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.Id.ToString().Equals(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.Email.Contains(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.PhoneNumber.Contains(searchValue)) ).ConfigureAwait(false); List <User> list = await _DbContext.Users .Include(u => u.Role) .Include(u => u.RegistrationMethod) .Where(u => filterRole.Equals(CoreConst.GetAllRecords) || u.Role.Id == filterRoleId) .Where(u => searchValue.Equals(CoreConst.GetAllRecords) || u.FirstName.Contains(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.Surname.Contains(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.Id.ToString().Equals(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.Email.Contains(searchValue) || searchValue.Equals(CoreConst.GetAllRecords) || u.PhoneNumber.Contains(searchValue)) .OrderByDynamic(sortName, isSortAsce) .Skip((selectedPage - 1) * maxItemsPerPage) .Take(maxItemsPerPage) .Include(u => u.Orders) .ToListAsync() .ConfigureAwait(false); list.ForEach(u => { u.OrderLength = u.Orders.Count(o => o.Status == OrderStatusType.Confirmed || o.Status == OrderStatusType.InProgress || (o.Dispute != null && o.Dispute.Status)); u.HasOrder = u.Orders.Count > 0; }); return(Ok(new MultiResult <List <User>, int>(list, totalCount, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> Silence() { try { User user = new User(); bool isAuthenticated = false; if (_SignInManager.IsSignedIn(User)) { foreach (string policy in AppFunc.GetCurrentRequestPolicies(Request)) { AuthorizationResult authResult = await _AuthService.AuthorizeAsync(User, policy).ConfigureAwait(false); if (authResult.Succeeded) { user = await _DbContext.Users .Include(u => u.Role) .Include(u => u.RegistrationMethod) .FirstOrDefaultAsync(u => u.Id == AppFunc.GetUserId(User)) .ConfigureAwait(false); isAuthenticated = true; break; } } } SetAntiforgeryCookie(); bool isUserAllowedInMaintenance = false; Request.Headers.TryGetValue("Origin", out StringValues OriginValue); if ((user.Role != null && (user.Role.AccessClaim == AppConst.AccessClaims.Admin || user.Role.AccessClaim == AppConst.AccessClaims.Manager)) || AppConst.Settings.AppDomains.AdminApp.EqualCurrentCultureIgnoreCase(OriginValue)) { isUserAllowedInMaintenance = true; } return(Ok(new MultiResult <User, bool, bool, bool> (user, isAuthenticated, AppConst.Settings.MaintenanceModeStatus, isUserAllowedInMaintenance , CoreFunc.GetCustomAttributeTypedArgument(ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
private async Task <IActionResult> Search( int selectedPage, int maxItemsPerPage, string filterCategory = CoreConst.GetAllRecords, string searchValue = CoreConst.GetAllRecords, string filterStatus = CoreConst.GetAllRecords, bool isSortAsce = true, string sortName = "Name") { try { _ = bool.TryParse(filterStatus, out bool boolFilterStatus); _ = int.TryParse(filterCategory, out int filterProductCategoryId); int totalCount = await _DbContext.Products .Where(p => filterStatus.Equals(CoreConst.GetAllRecords) || p.Status == boolFilterStatus) .Where(p => filterCategory.Equals(CoreConst.GetAllRecords) || p.Category.Id == filterProductCategoryId) .CountAsync(p => searchValue.Equals(CoreConst.GetAllRecords) || (p.Name.Contains(searchValue) || p.Id.ToString().Contains(searchValue))) .ConfigureAwait(false); /// Include the necessary properties List <Product> list = await _DbContext.Products .Where(p => filterStatus.Equals(CoreConst.GetAllRecords) || p.Status == boolFilterStatus) .Include(p => p.Category) .Include(p => p.NutritionalInfo) .Include(p => p.Comments) .Where(p => filterCategory.Equals(CoreConst.GetAllRecords) || p.Category.Id == filterProductCategoryId) .Where(p => searchValue.Equals(CoreConst.GetAllRecords) || (p.Name.Contains(searchValue) || p.Id.ToString().Contains(searchValue))) .OrderByDynamic(sortName, isSortAsce) .Skip((selectedPage - 1) * maxItemsPerPage) .Take(maxItemsPerPage) .ToListAsync() .ConfigureAwait(false); return(Ok(new MultiResult <List <Product>, int>(list, totalCount, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
[Authorize(AppConst.AccessPolicies.Secret)] /// Done public async Task <IActionResult> GetTemplate(int templateId) { try { var defaultTemplate = await _DbContext.EmailTemplates .SingleOrDefaultAsync(et => et.TemplateType.Equals(EmailTemplateTypes.DefaultTemplate)).ConfigureAwait(false); var template = await _DbContext.EmailTemplates .SingleOrDefaultAsync(et => et.Id == templateId).ConfigureAwait(false); defaultTemplate.PrepareDesign(WebHost.WebRootPath); template.PrepareDesign(WebHost.WebRootPath); template.SetServerClasses(); return(Ok(new MultiResult <EmailTemplate, EmailTemplate> (template, defaultTemplate, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> Get(int productId, int selectedPage = 1, int maxItemsPerPage = 5) { try { if (selectedPage == 0) { selectedPage = 1; } if (maxItemsPerPage == 0) { maxItemsPerPage = 5; } int totalCount = await _DbContext.Comments .CountAsync(c => c.Product.Id == productId) .ConfigureAwait(false); List <Comment> list = await _DbContext.Comments .Include(c => c.User) .Include(c => c.Product) .Where(c => c.Product.Id == productId) .OrderBy(c => c.Date) .Skip((selectedPage - 1) * maxItemsPerPage) .Take(maxItemsPerPage) .ToListAsync() .ConfigureAwait(false); Comment selectComment = null; if (AppFunc.GetUserId(User) != 0) { User user = await _DbContext.Users.Include(u => u.Orders) .ThenInclude(o => o.OrderItems).SingleOrDefaultAsync(u => u.Id == AppFunc.GetUserId(User)).ConfigureAwait(false); if (user.Orders.Any(o => o.Status == OrderStatusType.Delivered && o.OrderItems.Any(oi => oi.ProductId == productId))) { selectComment = await _DbContext.Comments.Include(c => c.User) .SingleOrDefaultAsync(c => c.Product.Id == productId && c.User.Id == AppFunc.GetUserId(User)); if (selectComment == null) { selectComment = new Comment() { Id = 0, Product = await _DbContext.Products.SingleOrDefaultAsync(p => p.Id == productId), User = user } } ; } } return(Ok(new MultiResult <List <Comment>, Comment, int>(list, selectComment, totalCount, CoreFunc.GetCustomAttributeTypedArgument(ControllerContext)))); } catch (Exception ex) { /// in the case any exceptions return the following error CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> All( int selectedPage, int maxNumberPerItemsPage, string searchValue = "", string filterStatus = CoreConst.GetAllRecords, bool isSortAsce = true, string sortName = "Date", string disputeFilter = CoreConst.GetAllRecords) { try { _ = bool.TryParse(disputeFilter, out bool boolDisputeFilter); bool closeDisput = await _DbContext.Orders.Include(o => o.Dispute) .AnyAsync(o => !o.Dispute.Status).ConfigureAwait(false); bool openDisput = await _DbContext.Orders.Include(o => o.Dispute) .AnyAsync(o => o.Dispute.Status).ConfigureAwait(false); int totalCount = await _DbContext.Orders .Include(o => o.User) .Include(o => o.Payment) .Include(o => o.Dispute) .Where(o => filterStatus.Equals(CoreConst.GetAllRecords) || o.Status.Equals((OrderStatusType)Enum.Parse(typeof(OrderStatusType), filterStatus, true))) .Where(o => disputeFilter.Equals(CoreConst.GetAllRecords) || o.Dispute.Status == boolDisputeFilter) .CountAsync(o => searchValue.Equals(CoreConst.GetAllRecords) || o.Name.Contains(searchValue) || o.User.FirstName.Contains(searchValue) || o.User.Surname.Contains(searchValue) || o.User.Email.Contains(searchValue) || o.Id.Contains(searchValue) || o.Postcode.Contains(searchValue) || o.Payment.Email.Contains(searchValue) || o.Payment.Reference.Contains(searchValue)) .ConfigureAwait(false); List <OrderStatusType> availebeStatusTypes = await _DbContext.Orders .Select(o => o.Status) .Distinct() .ToListAsync() .ConfigureAwait(false); List <Order> list = await _DbContext.Orders .Include(o => o.User) .Include(o => o.Payment) .Include(o => o.Dispute) .ThenInclude(c => c.Messages) .Where(o => filterStatus.Equals(CoreConst.GetAllRecords) || o.Status.Equals((OrderStatusType)Enum.Parse(typeof(OrderStatusType), filterStatus, true))) .Where(o => disputeFilter.Equals(CoreConst.GetAllRecords) || o.Dispute.Status == boolDisputeFilter) .Where(o => searchValue.Equals(CoreConst.GetAllRecords) || o.Name.Contains(searchValue) || o.User.FirstName.Contains(searchValue) || o.User.Surname.Contains(searchValue) || o.User.Email.Contains(searchValue) || o.Id.Contains(searchValue) || o.Postcode.Contains(searchValue) || o.Payment.Email.Contains(searchValue) || o.Payment.Reference.Contains(searchValue)) .OrderByDynamic(sortName, isSortAsce) .Skip((selectedPage - 1) * maxNumberPerItemsPage) .Take(maxNumberPerItemsPage) .Include(o => o.OrderItems) .ThenInclude(oi => oi.Product) .ToListAsync() .ConfigureAwait(false); return(Ok(new MultiResult <List <Order>, List <OrderStatusType>, int, DisputeFilterTypes>(list, availebeStatusTypes, totalCount, AppFunc.GetDisputeFilterTypes(closeDisput, openDisput), CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> Summary() { try { int newOrderCount = await _DbContext.Orders .CountAsync(o => o.Status == OrderStatusType.InProgress).ConfigureAwait(false); int openDisputeCount = await _DbContext.Communications .CountAsync(o => o.Type == ContactType.Dispute && o.Status == true).ConfigureAwait(false); int openMessageCount = await _DbContext.Communications .CountAsync(o => o.Type == ContactType.Message && o.Status == true).ConfigureAwait(false); decimal totalPrice = await _DbContext.Orders .Where(o => o.Status == OrderStatusType.InProgress || o.Status == OrderStatusType.Confirmed || o.Status == OrderStatusType.Delivered || o.Status == OrderStatusType.PartialyRefunded) .SumAsync(o => o.TotalPrice).ConfigureAwait(false); decimal totalPartialRefund = await _DbContext.Payments .Where(p => p.Type == PaymentType.PartialyRefunded) .SumAsync(p => p.RefundAmount).ConfigureAwait(false); return(Ok(new MultiResult <int, int, int, decimal>(newOrderCount, openDisputeCount, openMessageCount, totalPrice - totalPartialRefund, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> Search( int selectedPage, int maxNumberPerItemsPage, string searchValue = "", string filterStatus = CoreConst.GetAllRecords, bool isSortAsce = false, string sortName = "Date") { try { _ = bool.TryParse(filterStatus, out bool boolFilterStatus); int totalCount = await _DbContext.Communications .Where(c => c.Type == ContactType.Message && (filterStatus.Equals(CoreConst.GetAllRecords) || c.Status == boolFilterStatus)) .CountAsync(c => searchValue.Equals(CoreConst.GetAllRecords) || c.Id.Contains(searchValue) || c.FullName.Contains(searchValue) || c.Email.Contains(searchValue)) .ConfigureAwait(false); List <Communication> list = await _DbContext.Communications.Include(c => c.Order).ThenInclude(o => o.User) .Include(c => c.Messages) .Where(c => c.Type == ContactType.Message && (filterStatus.Equals(CoreConst.GetAllRecords) || c.Status == boolFilterStatus)) .Where(c => searchValue.Equals(CoreConst.GetAllRecords) || c.Id.Contains(searchValue) || c.FullName.Contains(searchValue) || c.Email.Contains(searchValue)) .OrderByDynamic(sortName, isSortAsce) .Skip((selectedPage - 1) * maxNumberPerItemsPage) .Take(maxNumberPerItemsPage) .ToListAsync() .ConfigureAwait(false); return(Ok(new MultiResult <List <Communication>, int>(list, totalCount, CoreFunc.GetCustomAttributeTypedArgument(ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }
public async Task <IActionResult> ProductAndRelate(string categoryName, string productName) { try { Product product = await _DbContext.Products .Include(p => p.Category) .Include(p => p.Comments) .Include(p => p.NutritionalInfo) .SingleOrDefaultAsync(p => p.Category.Name.Equals(categoryName) && p.Name.Equals(productName) && p.Status) .ConfigureAwait(false); if (product == null) { CoreFunc.Error(ref ErrorsList, "Product Not Found"); return(NotFound(ErrorsList)); } List <Product> relatedProducts = await _DbContext.Products .Include(p => p.Category) .Where(p => p.Category.Id == product.Category.Id && p.Id != product.Id && p.Status) .Take(3) .ToListAsync() .ConfigureAwait(false); if (relatedProducts.Count < 3) { relatedProducts.AddRange(await _DbContext.Products .Include(p => p.Category) .Take(3 - relatedProducts.Count) .Where(p => !relatedProducts.Contains(p) && p.Id != product.Id && p.Status) .ToListAsync() .ConfigureAwait(false)); } return(Ok(new MultiResult <Product, List <Product> >(product, relatedProducts, CoreFunc.GetCustomAttributeTypedArgument(this.ControllerContext)))); } catch (Exception ex) { CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User)); return(StatusCode(417, ErrorsList)); } }