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)); }
/// <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> /// show support list in listview with jquery datatabale /// </summary> /// <returns></returns> public IActionResult List() { try { var dtValues = SetDataTableRequest(); int recordsTotal = 0; var data = _mapper.Map <List <SupportDto> >(_uow.SupportRepo.Filter(dtValues.draw, dtValues.length, dtValues.sortColumn, dtValues.sortColumnDirection, dtValues.searchValue, dtValues.pageSize, dtValues.skip, ref recordsTotal, UserExtention.GetUserId(User), "SupportType")); dtValues.recordsTotal = recordsTotal; return(Json(new AjaxResult { draw = dtValues.draw, recordsFiltered = dtValues.recordsTotal, recordsTotal = dtValues.recordsTotal, data = data })); } catch (Exception ex) { return(Json("error")); } }