public async Task <IHttpActionResult> Post(CreateSuperUserDTO model) { if (string.IsNullOrEmpty(model.Email)) { return(BadRequest("Email address is required")); } if (string.IsNullOrEmpty(model.Password)) { return(BadRequest("Password is required")); } var platformUser = new PlatformUser { Id = Guid.NewGuid(), UserName = model.Email, Email = model.Email, FirstName = model.FirstName, Surname = model.Surname }; try { UnitOfWork.UserManager.AddOrUpdateUser(platformUser, model.Password); await UnitOfWork.UserManager.AddToRoleAsync(platformUser.Id, Role.PLATFORM_ADMINISTRATOR); MemoryCacher.Delete(CACHE_KEY); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult LogOff() { var re = Request; var authorization = re.Headers.Authorization; if (authorization != null && authorization.Scheme == "Bearer") { if (string.IsNullOrEmpty(authorization.Parameter)) { } else { var token = new JwtSecurityToken(jwtEncodedString: authorization.Parameter); foreach (var item in token.Claims) { if (item.Type == "unique_name") { MemoryCacher.Delete(item.Value); break; } } } } FormsAuthentication.SignOut(); return(Ok(new { success = true, message = "Đăng xuất thành công!" })); }
public async Task ChunkDataUploadSvr(ChunkData chunk) { await Task.Run(() => { string chunkKey = chunk.ChunkKey; string chunkKeyNumber = chunk.ChunkCurrent.ToString(); double minutes = chunk.ChunkTimeMinutes; chunkKey = chunkKey + "_" + chunkKeyNumber; cacher.Delete(chunkKey);//make sure only one key on cacher cacher.AddMinutes(chunkKey, chunk, minutes); }); }
private static void CacheDetails(UserDetailsViewModel userDetailViewModel, string storageKey, string storageName, string organizationId, string signedInUserUniqueId) { if (!string.IsNullOrEmpty(storageName) && !string.IsNullOrEmpty(storageKey)) { CacheUserDetails cud = new CacheUserDetails(); cud.SubscriptionId = userDetailViewModel.SubscriptionId; cud.StorageName = storageName; cud.OrganizationId = organizationId; cud.StorageKey = storageKey; MemoryCacher.Delete(signedInUserUniqueId); MemoryCacher.Add(signedInUserUniqueId, cud, DateTime.Now.AddMinutes(15)); } }
public HttpResponseMessage ChangePassword([FromUri] int id, PasswordModel passwordModel) { var identity = (ClaimsIdentity)User.Identity; if (identity.Name != id.ToString()) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid Token")); } using (var db = new OnlineMusicEntities()) { try { var user = (from u in db.Users where u.Id == id select u).FirstOrDefault(); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Tài khoản với id={id} không tồn tại")); } else { MemoryCacher cache = new MemoryCacher(); string cachePassword = cache.Get(user.Username) != null ? (string)cache.Get(user.Username) : String.Empty; bool isValid = HashingPassword.ValidatePassword(passwordModel.OldPassword, user.Password); if (!isValid) { // Try check cache password isValid = !String.IsNullOrEmpty(cachePassword) && HashingPassword.ValidatePassword(passwordModel.OldPassword, cachePassword); } if (!isValid) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Mật khẩu cũ không đúng")); } else { user.Password = HashingPassword.HashPassword(passwordModel.NewPassword); cache.Delete(user.Username); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } } }
public IHttpActionResult Post([FromBody] SubscriptionPlanDTO value) { var plan = Mapper.Map <SubscriptionPlan>(value); try { UnitOfWork.SubscriptionPlansRepository.InsertOrUpdate(plan); UnitOfWork.Save(); MemoryCacher.Delete(CACHE_KEY); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Post([FromBody] VoucherDTO value) { var voucher = Mapper.Map <Voucher>(value); voucher.OrganisationId = Guid.Parse(value.Organisation.Id); voucher.Organisation = null; try { UnitOfWork.VouchersRepository.InsertOrUpdate(voucher); UnitOfWork.Save(); MemoryCacher.Delete(CACHE_KEY); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public HttpResponseMessage Logout() { try { IEnumerable <string> _sessionGuid; if (Request.Headers.TryGetValues("SessionGuid", out _sessionGuid)) { MemoryCacher.Delete(_sessionGuid.First()); return(Request.CreateResponse(HttpStatusCode.OK, new { SessionGuid = _sessionGuid.First() })); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch (Exception ex) { LogGenerationHelper.WriteToFile(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public ChunkData ChunkDataUploadSvrSync(ChunkData chunk) { /*Gak dipake*/ MemoryCacher cacher = new MemoryCacher(); ChunkData result = new ChunkData(); string savedchunk = string.Empty; object checkchunk = null; //check apakah ada data chunk checkchunk = cacher.GetValue(chunk.ChunkKey); result.ChunkCurrent = chunk.ChunkCurrent; result.ChunkKey = chunk.ChunkKey; result.ChunkMaxCount = chunk.ChunkMaxCount; result.FileName = chunk.FileName; if (checkchunk != null) { //resultchunk =jika ada, data chunk lama + data terbaru savedchunk = (string)checkchunk; result.DataChunk = savedchunk + chunk.DataChunk; } else { //resultchunk =jika tidak ada, data terbaru result.DataChunk = chunk.DataChunk; } //menghapus data chace cacher.Delete(chunk.ChunkKey); if (chunk.ChunkMaxCount == chunk.ChunkCurrent) { result.CompleteChunk = true; } else { result.CompleteChunk = false; //membuat chache data chace cacher.AddMinutes(result.ChunkKey, result.DataChunk, chunk.ChunkTimeMinutes); } return(result); }
private void InitState() { MemoryCacher.Delete(Constant.PaymentPerMonthList); MemoryCacher.Add(Constant.PaymentPerMonthList, Mapper.Map <List <PaymentGridItemDto> >(_paymentPerMonthRepository.GetAll().ToList()), DateTimeOffset.Now.AddMinutes(Constant.CacheTime)); }
public static void AddCurrentSaleForTill(int tillNumber, int saleNumber, Sale sale) { MemCacher.Delete($"CURRENTSALE_{tillNumber}_{saleNumber}"); MemCacher.Add($"CURRENTSALE_{tillNumber}_{saleNumber}", sale, DateTimeOffset.UtcNow.AddHours(1)); }
private void InitState() { MemoryCacher.Delete(Constant.MonthlyBudgetList); MemoryCacher.Add(Constant.MonthlyBudgetList, (List <MonthlyBudgetGridItemDto>)MemoryCacher.GetValue(Constant.MonthlyBudgetList), DateTimeOffset.Now.AddMinutes(Constant.CacheTime)); }
private void ClearMenuCache() { MemoryCacher.Delete(Cache.Menu); }
private void InitState() { MemoryCacher.Delete(Constant.CategoryList); MemoryCacher.Add(Constant.CategoryList, Mapper.Map <List <CategoryGridItemDto> >(_categoryRepository.GetAll().ToList()), DateTimeOffset.Now.AddMinutes(Constant.CacheTime)); }