/// <summary> /// get affiliate ConversionRate as Pie Chart for report /// </summary> /// <returns></returns> public ActionResult ConversionRate() { StiReport stiReport = new StiReport(); stiReport.Load(StiNetCoreHelper.MapPath(this, "wwwroot/Reports/ConversionRateReport.mrt")); var affiliates = _uow.AffiliateRepo.Get(d => d.Email == UserExtention.GetUserMail(User)).FirstOrDefault(); var registeredSells = _uow.SellRepo.Get(d => d.AffiliateCode == affiliates.Code && d.PayStatus == PayStatus.Registered); stiReport["RegisteredSell"] = registeredSells != null?registeredSells.Sum(d => d.Price) : 0; var AllSells = _uow.SellRepo.Get(d => d.AffiliateCode == affiliates.Code && d.PayStatus != PayStatus.Registered); stiReport["AllSellValue"] = AllSells != null?AllSells.Sum(d => d.Price) : 0; return(StiNetCoreViewer.GetReportResult(this, stiReport)); }
public UserExtention GetUserExtention(int userId) { UserExtention model = new UserExtention(); using (DataCommand cmd = DataCommandManager.GetDataCommand("GetUserInfo")) { cmd.SetParameterValue("@UserId", userId); using (IDataReader dr = cmd.ExecuteDataReader()) { while (dr.Read()) { if (!Convert.IsDBNull(dr["UserId"])) { model.UserId = Convert.ToInt32(dr["UserId"]); } if (!Convert.IsDBNull(dr["NickName"])) { model.NickName = dr["NickName"].ToString(); } if (!Convert.IsDBNull(dr["Name"])) { model.Name = dr["UserId"].ToString(); } if (!Convert.IsDBNull(dr["OrganizationId"])) { model.OrganizationId = Convert.ToInt32(dr["OrganizationId"]); } if (!Convert.IsDBNull(dr["FullName"])) { model.OrganizationName = dr["FullName"].ToString(); } if (!Convert.IsDBNull(dr["RoleId"])) { model.RoleId = Convert.ToInt32(dr["RoleId"]); } if (!Convert.IsDBNull(dr["RoleName"])) { model.RoleName = dr["RoleName"].ToString(); } } } } return(model); }
public async Task <IActionResult> Create(SupportDto supportDto) { if (ModelState.IsValid) { try { if (supportDto.Attachment != null) { var File = Guid.NewGuid().ToString() + Path.GetExtension(supportDto.Attachment.FileName); string savePath = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/supportImages", File ); string DirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/supportImages"); Upload uploader = new Upload(); supportDto.File = Request.Scheme + "://" + Request.Host.Value + "/supportImages/" + File; await uploader.UploadImage(savePath, DirectoryPath, supportDto.Attachment); } var model = _mapper.Map <Tb_Support>(supportDto); model.SenderUserId = UserExtention.GetUserId(User); model.Email = UserExtention.GetUserMail(User); model.SupportPosition = SupportPosition.Pending; await _uow.SupportRepo.InsertAsync(model); await _uow.SaveAsync(); // Call signalr api for show notification in admin panel supportDto.Id = model.Id; if (!await SendDataToSignalR(model)) // if send notif with signalr has failed { return(Json(new { success = "Support messages added successfully, But The send notification to admin failed \n" })); } return(View(supportDto)); } catch (Exception e) { return(Json(new { error = "The operation failed \n" + e.Message })); } } return(View(supportDto)); }
public UserExtention GetUser(int id) { string queryString = @"SELECT Users.Id,Roles.IsAllowed,Roles.Role,Users.UserName FROM Users INNER JOIN Roles ON Users.RoleId = Roles.Id Where Users.Id = @Id"; using (SqlConnection connection = new SqlConnection(Connections.GetConnectionString())) { SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@Id", id); try { connection.Open(); UserExtention user; SqlDataReader reader = command.ExecuteReader(); string userId = string.Empty; while (reader.Read()) { user = new UserExtention { Id = reader.GetInt32(0), IsAllowed = reader.GetBoolean(1), UserName = reader.GetString(3), RoleDescription = reader.GetString(2), }; reader.Close(); return(user); } reader.Close(); } catch (Exception e) { return(null); } return(null); } }
/// <summary> /// show dashboard items as ajax json by DateTime parameter /// </summary> /// <param name="filterValue"></param> /// <returns></returns> public JsonResult GetDashboardActivities(int filterValue = 0) { var userPurchases = _mapper.Map <IEnumerable <SellDto> >(_uow.SellRepo.GetPurchasesOnDashboard(5, UserExtention.GetUserMail(User), filterValue)); var registered = filterValue == 0 ? _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus == PayStatus.Registered) : _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus == PayStatus.Registered && d.CreateAt > DateTime.Now.AddDays(-filterValue)); var RegisteredCount = registered == null ? 0 : registered.Count(); var purchases = filterValue == 0 ? _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus != PayStatus.Registered) : _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus != PayStatus.Registered && d.CreateAt > DateTime.Now.AddDays(-filterValue)); var SumPurchases = purchases != null?purchases.Sum(d => d.Price) : 0; var CountPurchases = purchases != null?purchases.Count() : 0; return(Json(new { UserPurchases = userPurchases, RegisteredCount = RegisteredCount, SumPurchases = SumPurchases, PurchasesCount = CountPurchases, })); }
//// <summary> /// show list view in View as Datatable jquery /// </summary> /// <returns></returns> public IActionResult List() { try { var dtValues = SetDataTableRequest(); int recordsTotal = 0; var data = _uow.SellRepo.AffiliateCustomers(dtValues.draw, dtValues.length, dtValues.sortColumn, dtValues.sortColumnDirection, dtValues.searchValue, dtValues.pageSize, dtValues.skip, ref recordsTotal, UserExtention.GetUserMail(User)); List <SellDto> list = new List <SellDto>(); foreach (var email in data) { var model = new SellDto() { Email = email }; list.Add(model); } dtValues.recordsTotal = recordsTotal; return(Json(new AjaxResult { draw = dtValues.draw, recordsFiltered = dtValues.recordsTotal, recordsTotal = dtValues.recordsTotal, data = list })); } catch (Exception ex) { return(Json("error")); } }
/// <summary> /// show list view in View as Datatable jquery /// </summary> /// <returns></returns> public IActionResult List() { try { var dtValues = SetDataTableRequest(); int recordsTotal = 0; var data = _mapper.Map <List <SellDto> >(_uow.SellRepo.Filter(dtValues.draw, dtValues.length, dtValues.sortColumn, dtValues.sortColumnDirection, dtValues.searchValue, dtValues.pageSize, dtValues.skip, ref recordsTotal, UserExtention.GetUserMail(User))); dtValues.recordsTotal = recordsTotal; return(Json(new AjaxResult { draw = dtValues.draw, recordsFiltered = dtValues.recordsTotal, recordsTotal = dtValues.recordsTotal, data = data })); } catch (Exception ex) { return(Json("error")); } }
/// <summary> /// manage user profile /// </summary> /// <returns></returns> public async Task <IActionResult> Profile() { try { var userDto = _mapper.Map <ProfileDto>(await _userManager.FindByIdAsync(UserExtention.GetUserId(User))); if (userDto == null) { ViewBag.ErrorMessage = ErrorMessageForGetInformation; return(View()); } return(View(userDto)); } catch (Exception ex) { ViewBag.ErrorMessage = ErrorMessageForGetInformation + " \n " + ex.Message; return(View()); } }
/// <summary> /// show dashboard items as ajax json by DateTime parameter /// </summary> /// <param name="filterValue"></param> /// <returns></returns> public JsonResult GetDashboardActivities(int filterValue = 0) { string affiliateCode = ""; var AllAffiliatesells = _mapper.Map <IEnumerable <SellDto> >(_uow.SellRepo.GetSellOnDashboard(5, UserExtention.GetUserId(User), ref affiliateCode, filterValue)); var registered = filterValue == 0 ? _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.PayStatus == PayStatus.Registered) : _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.PayStatus == PayStatus.Registered && d.CreateAt > DateTime.Now.AddDays(-filterValue)); ViewBag.Registered = registered == null ? 0 : registered.Count(); var Allsells = filterValue == 0 ? _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode) : _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.CreateAt > DateTime.Now.AddDays(-filterValue)); var AllsellCount = Allsells == null ? 0 : Allsells.Count(); var sumSell = filterValue == 0 ? _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.PayStatus != PayStatus.Registered) : _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.PayStatus != PayStatus.Registered && d.CreateAt > DateTime.Now.AddDays(-filterValue)); var countSell = sumSell == null ? 0 : sumSell.Count(); ViewBag.sumSell = sumSell == null ? 0 : sumSell.Sum(d => d.Price); var userSells = filterValue == 0 ? _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.PayStatus != PayStatus.Registered) .GroupBy(m => m.ProductName) .Select(d => new ProductSellDto { ProductName = d.Key, SellCount = d.Count() }) .OrderBy(x => x.ProductName).ToList() : _uow.SellRepo.Get(d => d.AffiliateCode == affiliateCode && d.PayStatus != PayStatus.Registered && d.CreateAt > DateTime.Now.AddDays(-filterValue)) .GroupBy(m => m.ProductName) .Select(d => new ProductSellDto { ProductName = d.Key, SellCount = d.Count() }) .OrderBy(x => x.ProductName).ToList(); ViewBag.Sells = userSells.Where(d => d.ProductName != "").Count(); var comision = _uow.AffiliateRepo.Get(d => d.Email == UserExtention.GetUserMail(User)).FirstOrDefault(); ViewBag.Comision = comision == null ? 0 : comision.comision; var click = _uow.AffiliateRepo.Get(d => d.Email == UserExtention.GetUserMail(User)).FirstOrDefault(); ViewBag.Clicks = click == null ? 0 : click.Click; ViewBag.CommisionAmount = (ViewBag.sumSell * ViewBag.Comision) / 100; if (countSell == 0 && AllsellCount == 0) { ViewBag.Conversion = 0; } else { ViewBag.Conversion = countSell / AllsellCount; } return(Json(new { AllAffiliatesells = AllAffiliatesells, Registered = ViewBag.Registered, SumSell = ViewBag.sumSell, Sells = ViewBag.Sells, Comistion = ViewBag.Comision, Clicks = ViewBag.Clicks, CommisionAmount = ViewBag.CommisionAmount, Conversion = ViewBag.Conversion })); }
/// <summary> /// get UserPurchases for report /// </summary> /// <returns></returns> public ActionResult UserPurchases() { try { var model = new SellReportDto(); if (TempData["StartDate"] != null) { model.StartDate = DateTime.Parse(TempData["StartDate"].ToString()); } if (TempData["EndDate"] != null) { model.EndDate = DateTime.Parse(TempData["EndDate"].ToString()); } if (TempData["FilterType"] != null) { model.FilterType = (FilterType)(TempData["FilterType"]); } if (TempData["SkipDate"] != null) { model.SkipDate = (bool)(TempData["SkipDate"]); } StiReport stiReport = new StiReport(); stiReport.Load(StiNetCoreHelper.MapPath(this, "wwwroot/Reports/UserBuyReport.mrt")); IEnumerable <Tb_Sell> userPurchases = null; switch (model.FilterType) { case FilterType.All: userPurchases = !model.SkipDate ? _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.CreateAt >= model.StartDate && d.CreateAt <= model.EndDate) : _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User)); break; case FilterType.OnlyRegister: userPurchases = !model.SkipDate ? _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus == PayStatus.Registered && d.CreateAt >= model.StartDate && d.CreateAt <= model.EndDate) : _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus == PayStatus.Registered); break; case FilterType.Sells: userPurchases = !model.SkipDate ? _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus != PayStatus.Registered && d.CreateAt >= model.StartDate && d.CreateAt <= model.EndDate) : _uow.SellRepo.Get(d => d.Email == UserExtention.GetUserMail(User) && d.PayStatus != PayStatus.Registered); break; default: break; } var sumSell = userPurchases.Sum(d => d.Price); stiReport["SumBuy"] = sumSell.ToString("N0"); stiReport.RegData("userPurchasesDT", userPurchases); return(StiNetCoreViewer.GetReportResult(this, stiReport)); } catch (Exception ex) { return(null); } }