public void UpdateAlbum(ref Album album, int accountId) { album.Modified = DateTime.UtcNow; album.ModifiedBy = accountId; RepositoryContext.Albums.Update(album); RepositoryContext.SaveChanges(); }
public void CreateAlbum(ref Album album, int accountId) { album.Created = DateTime.UtcNow; album.CreatedBy = accountId; RepositoryContext.Albums.Add(album); RepositoryContext.SaveChanges(); }
public void UpdateEvent(ref Event calendarEvent, int accountId) { calendarEvent.Updated = DateTime.UtcNow; calendarEvent.UpdatedBy = accountId; RepositoryContext.Events.Update(calendarEvent); RepositoryContext.SaveChanges(); }
public void DeactivateOfficer(Officer officer, int accountId) { officer.Active = false; officer.Updated = DateTime.UtcNow; officer.UpdatedBy = accountId; RepositoryContext.Officers.Update(officer); RepositoryContext.SaveChanges(); }
public void SaveVerificationToken(string token, ref Account account) { account.Verified = DateTime.UtcNow; account.VerificationToken = null; RepositoryContext.Accounts.Update(account); RepositoryContext.SaveChanges(); }
public Content UpdateContent(ref Content content, int accountId) { content.Updated = DateTime.UtcNow; content.LastUpdatedUserId = accountId; RepositoryContext.Update(content); RepositoryContext.SaveChanges(); return(content); }
public void DeactivateCommitteeMember(ref CommitteeMember member, int accountId) { member.Active = false; member.Updated = DateTime.UtcNow; member.UpdatedBy = accountId; RepositoryContext.CommitteeMembers.Update(member); RepositoryContext.SaveChanges(); }
public Account Update(ref Account account) { account.Updated = DateTime.UtcNow; RepositoryContext.Accounts.Update(account); RepositoryContext.SaveChanges(); return(account); }
public Account Create(ref Account account) { // save account account.Created = DateTime.UtcNow; account.Verified = DateTime.UtcNow; RepositoryContext.Accounts.Add(account); RepositoryContext.SaveChanges(); return(account); }
public void RevokeToken(string token, string ipAddress) { var(refreshToken, account) = getRefreshToken(token); // revoke token and save refreshToken.Revoked = DateTime.UtcNow; refreshToken.RevokedByIp = ipAddress; RepositoryContext.Update(account); RepositoryContext.SaveChanges(); }
public void Authenticate(string ipAddress, string secret, ref Account account, out string jwtToken, out RefreshToken refreshToken) { // authentication successful so generate jwt and refresh tokens jwtToken = generateJwtToken(account, secret); refreshToken = generateRefreshToken(ipAddress); // save refresh token account.RefreshTokens?.Add(refreshToken); RepositoryContext.Update(account); RepositoryContext.SaveChanges(); }
public void ResetPassword(ResetPasswordRequest model, Account account) { // update password and remove reset token account.PasswordHash = BC.HashPassword(model.Password); account.PasswordReset = DateTime.UtcNow; account.ResetToken = null; account.ResetTokenExpires = null; RepositoryContext.Accounts.Update(account); RepositoryContext.SaveChanges(); }
public void CreatePhotos(ref IEnumerable <Photo> photos, int accountId) { foreach (var photo in photos) { photo.Created = DateTime.UtcNow; photo.AddedBy = accountId; RepositoryContext.Photos.Add(photo); } RepositoryContext.SaveChanges(); }
public Officer UpdateOfficer(ref Officer officer, int accountId, int?memberId) { if (memberId != null) { officer.MemberId = memberId; } officer.Updated = DateTime.UtcNow; officer.UpdatedBy = accountId; RepositoryContext.Officers.Update(officer); RepositoryContext.SaveChanges(); return(officer); }
public CommitteeMember UpdateCommitteeMember(ref CommitteeMember member, int accountId, int?memberId) { if (memberId != null) { member.MemberId = memberId; } member.Updated = DateTime.UtcNow; member.UpdatedBy = accountId; RepositoryContext.CommitteeMembers.Update(member); RepositoryContext.SaveChanges(); return(member); }
public void Register(RegisterRequest model, string origin, Account account, IEmailService emailService) { // first registered account is an admin var isFirstAccount = !RepositoryContext.Accounts.Any(); account.Role = isFirstAccount ? Role.Admin : Role.Member; account.Created = DateTime.UtcNow; account.VerificationToken = randomTokenString(); // save account RepositoryContext.Accounts.Add(account); RepositoryContext.SaveChanges(); // send email sendVerificationEmail(account, origin, emailService); }
public Officer AddOfficer(ref Officer officer, int?accountId, int?memberId) { if (accountId != null) { officer.CreatedBy = accountId; } if (memberId != null) { officer.MemberId = memberId; } officer.Created = DateTime.UtcNow; RepositoryContext.Officers.Add(officer); RepositoryContext.SaveChanges(); return(officer); }
public Account RefreshToken(string token, string ipAddress, string secret, out string jwtToken, out RefreshToken newRefreshToken) { var(refreshToken, account) = getRefreshToken(token); // replace old refresh token with a new one and save newRefreshToken = generateRefreshToken(ipAddress); refreshToken.Revoked = DateTime.UtcNow; refreshToken.RevokedByIp = ipAddress; refreshToken.ReplacedByToken = newRefreshToken.Token; account.RefreshTokens.Add(newRefreshToken); RepositoryContext.Update(account); RepositoryContext.SaveChanges(); // generate new jwt jwtToken = generateJwtToken(account, secret); return(account); }
public static void Initialize(RepositoryContext context) { context.Database.Migrate(); if (context.Users.Any()) { return; } context.Users.Add(new User() { // Todo: вынести логин и пароль в кофиг Name = "admin", PasswordHash = IdentityHelper.GetPasswordHash("admin"), Role = Role.Admin }); context.SaveChanges(); }
public void ForgotPassword(ForgotPasswordRequest model, string origin, IEmailService emailService) { var account = RepositoryContext.Accounts.SingleOrDefault(x => x.Email == model.Email); // always return ok response to prevent email enumeration if (account == null) { return; } // create reset token that expires after 1 day account.ResetToken = randomTokenString(); account.ResetTokenExpires = DateTime.UtcNow.AddDays(24); RepositoryContext.Accounts.Update(account); RepositoryContext.SaveChanges(); // send email sendPasswordResetEmail(account, origin, emailService); }
public CommitteeMember CreateCommitteeMember(ref CommitteeMember member, int?accountId, int?memberId) { member.Created = DateTime.UtcNow; if (accountId == null) { } else { member.CreatedBy = accountId; } if (memberId != null) { member.MemberId = memberId; } RepositoryContext.CommitteeMembers.Add(member); RepositoryContext.SaveChanges(); return(member); }
public void Save() { _repositoryContext.SaveChanges(); }
public void Save() { _repoContext.SaveChanges(); }
public void DeletePhoto(Photo photo) { RepositoryContext.Photos.Remove(photo); RepositoryContext.SaveChanges(); }
//Kiểm tra collection truyền vào có tên trùng trong database không //KQ: false = TruyenID hoặc TheLoaiID không tồn tại, true: thêm thành công public ResponseDetails CreateNoiDungChuong(IEnumerable <NoiDungChuong> noiDungChuongs) { /*Kiểm tra xem chuỗi json nhập vào có bị trùng tên chương không*/ foreach (var dup in noiDungChuongs.GroupBy(p => p.HinhAnh)) { if (dup.Count() - 1 > 0) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Chuỗi json nhập vào bị trùng đường dẫn ảnh", Value = dup.Key.ToString() }); } } /*End*/ var chuongRepo = new ChuongRepository(_context); foreach (var nd in noiDungChuongs) { /*Bắt lỗi [ID]*/ if (!chuongRepo.FindByCondition(t => t.ChuongID.Equals(nd.ChuongID)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "ID chương không tồn tại", Value = nd.ChuongID.ToString() }); } /*End*/ /*Bắt lỗi [Tên hình ảnh]*/ if (FindByCondition(t => t.HinhAnh.Equals(nd.HinhAnh) && t.ChuongID.Equals(nd.ChuongID)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Chương đã tồn tại hình ảnh này", Value = nd.HinhAnh }); } if (FindByCondition(t => t.HinhAnh.Equals(nd.HinhAnh)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Hình ảnh này đã nằm trong 1 chương khác", Value = nd.HinhAnh }); } /*End*/ //Tạo dữ liệu nhưng chưa add vào CSDL Create(nd); _context.SaveChanges(); } return(new ResponseDetails() { StatusCode = ResponseCode.Success, Message = "Thêm nội dung chương thành công" }); }
//Kiểm tra collection truyền vào có tên trùng trong database không //KQ: !null = TenChuong bị trùng, null: thêm thành công public ResponseDetails CreateChuong(IEnumerable <Chuong> chuongs) { /*Kiểm tra xem chuỗi json nhập vào có bị trùng tên chương không*/ foreach (var dup in chuongs.GroupBy(p => p.TenChuong)) { if (dup.Count() - 1 > 0) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Chuỗi json nhập vào bị trùng tên chương", Value = dup.Key.ToString() }); } } /*End*/ foreach (var chuong in chuongs) { /*Bắt lỗi [ID]*/ var truyenRepo = new TruyenRepository(_context); if (!truyenRepo.FindByCondition(t => t.TruyenID.Equals(chuong.TruyenID)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "ID truyện không tồn tại", Value = chuong.TruyenID.ToString() }); } /*End*/ /*Bắt lỗi [Tên chương]*/ if (FindByCondition(t => t.TenChuong.Equals(chuong.TenChuong) && t.TruyenID.Equals(chuong.TruyenID)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Tên chương bị trùng", Value = chuong.TenChuong }); } /*End*/ var found = FindByCondition(m => m.TruyenID.Equals(chuong.TruyenID)); if (found.Count() > 0) { chuong.STT = found.Max(m => m.STT) + 1; } else { chuong.STT = 1; } chuong.ThoiGianCapNhat = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Random r = new Random(); chuong.LuotXem = r.Next(5000, 15000); //Tạo dữ liệu nhưng chưa add vào CSDL Create(chuong); _context.SaveChanges(); } return(new ResponseDetails() { StatusCode = ResponseCode.Success }); }
public void Delete(Account account) { RepositoryContext.Accounts.Remove(account); RepositoryContext.SaveChanges(); }
public void DeleteAlbum(Album album) { RepositoryContext.Albums.Remove(album); RepositoryContext.SaveChanges(); }
//Kiểm tra collection truyền vào có tên trùng trong database không //KQ: !null = TenTruyen bị trùng, null: thêm thành công public ResponseDetails CreateTruyen(IEnumerable <Truyen> truyens) { /*Kiểm tra xem chuỗi json nhập vào có bị trùng tên truyện không*/ foreach (var dup in truyens.GroupBy(p => p.TenTruyen)) { if (dup.Count() - 1 > 0) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Chuỗi json nhập vào bị trùng tên truyện", Value = dup.Key.ToString() }); } } /*End*/ /*Kiểm tra xem chuỗi json nhập vào có bị trùng hình ảnh không*/ foreach (var dup in truyens.GroupBy(p => p.HinhAnh)) { if (dup.Count() - 1 > 0) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Chuỗi json nhập vào bị trùng hình ảnh truyện", Value = dup.Key.ToString() }); } } /*End*/ var tacGiaRepo = new TacGiaRepository(_context); foreach (var truyen in truyens) { /*Bắt lỗi [ID]*/ if (!tacGiaRepo.FindByCondition(t => t.TacGiaID.Equals(truyen.TacGiaID)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "ID tác giả không tồn tại", Value = truyen.TacGiaID.ToString() }); } /*End*/ /*Bắt lỗi [Tên truyện]*/ if (FindByCondition(t => t.TenTruyen.Equals(truyen.TenTruyen)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Tên truyện bị trùng", Value = truyen.TenTruyen }); } /*End*/ /*Bắt lỗi [Hình ảnh]*/ if (FindByCondition(t => t.HinhAnh.Equals(truyen.HinhAnh)).Any()) { return(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "Hình ảnh này đã tồn tại", Value = truyen.TenTruyen + ": " + truyen.HinhAnh }); } /*End*/ truyen.TenTruyen = truyen.TenTruyen.ToLower(); Create(truyen); _context.SaveChanges(); } return(new ResponseDetails() { StatusCode = ResponseCode.Success }); }
protected void TrySave() { RepositoryContext.SaveChanges(); }