public ActionResult SellAccount(int accountId) { var account = _accountService.ReadOneById(accountId); var user = _userService.ReadByGeneralUserId(User.Identity.GetUserId()); if ((account.Price - ((account.Price * account.EventPrice) / 100)) > UserExternalService.GetUserBalance(User.Identity.GetUserId())) { return(RedirectToAction("ChargingView", "User", new { Message = "Tài khoản quý khách không đủ tiền, xin vui lòng nạp thêm. Cám ơn !" })); } try { _accountService.SoldAccount(accountId); //delete image FileUlti.DeleteFile(Server.MapPath("~") + account.Avatar.Substring(2)); foreach (var page in account.NumberOfPageGems) { FileUlti.DeleteFile(Server.MapPath("~") + page.ImageUrl.Substring(2)); } var sumOfBalance = user.Balance - (account.Price - ((account.Price * account.EventPrice) / 100)); _userService.UpdateBalanceUser(user.GeneralUserId, sumOfBalance); } catch (Exception) { } try { if (user != null) { _historyService.Create(new UserTradingHistoryDto() { AccountId = account.Id, UserId = user.Id, CreatedDate = DateTime.Now }); } } catch (Exception) { throw; } AccountSoldViewModel vm = new AccountSoldViewModel() { AccountName = account.UserName, Password = account.Password, Description = account.Description }; return(View(vm)); }
public ActionResult DeleteWheelItem(int id = 0) { var result = _userService.DeleteLuckyItem(id); if (!string.IsNullOrEmpty(result)) { FileUlti.DeleteFile(Server.MapPath("~") + result.Substring(2)); } return(RedirectToAction("WheelManagement")); }
public int DeletePageGemById(int pageGemId) { var imagesDeleted = _pageGemRepositories.ReadOne(a => a.Id == pageGemId); _pageGemRepositories.Delete(a => a.Id == pageGemId); int result = _pageGemRepositories.SaveChanges(); if (result > 0) { FileUlti.DeleteFile(imagesDeleted.ImageUrl); } return(result); }
public int DeletePageGemByAccountId(int accountId) { var imagesDeleted = _pageGemRepositories.Read(a => a.AccountId == accountId).Select(a => a.ImageUrl); _pageGemRepositories.Delete(a => a.AccountId == accountId); int result = _pageGemRepositories.SaveChanges(); if (result > 0) { foreach (var img in imagesDeleted) { FileUlti.DeleteFile(img); } } return(result); }
public ActionResult ClearImage() { var data = _accountService.Read(false); foreach (var item in data) { if (!item.IsAvailable) { FileUlti.DeleteFile(Server.MapPath("~") + item.Avatar.Substring(2)); foreach (var page in item.NumberOfPageGems) { FileUlti.DeleteFile(Server.MapPath("~") + page.ImageUrl.Substring(2)); } } } return(RedirectToAction("Index")); }
public int Delete(int entityId) { var avatar = _repoAccount.ReadOne(a => a.Id == entityId).Avatar; var data = _repoAccount.ReadOne(a => a.Id == entityId).NumberOfPageGems.Select(a => a.ImageUrl).ToList(); _repoAccount.Delete(a => a.Id == entityId); var result = _repoAccount.SaveChanges(); if (result > 0) { FileUlti.DeleteFile(avatar); foreach (var page in data) { FileUlti.DeleteFile(page); } } return(result); }