public override async Task <int> Handle(AdminMenuUpdateFieldCommand request, CancellationToken cancellationToken) { switch (request.Field.ToLower()) { case "icon": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == request.Id, c => new AdminMenuEntity() { Icon = request.Value, Updated_At = DateTime.Now })); case "url": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == request.Id, c => new AdminMenuEntity() { Url = request.Value, Updated_At = DateTime.Now })); case "onlycode": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == request.Id, c => new AdminMenuEntity() { OnlyCode = request.Value, Updated_At = DateTime.Now })); case "weight": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == request.Id, c => new AdminMenuEntity() { Weight = request.Value.ToInt(), Updated_At = DateTime.Now })); default: return(0); } }
public async Task <int> UpdateAsync(long id, string field, string value, CancellationToken cancellationToken) { switch (field.ToLower()) { case "name": return(await db.UpdateAsync <AdminRoleEntity>(c => c.Id == id, c => new AdminRoleEntity() { Name = value, Updated_At = DateTime.Now }, cancellationToken)); default: return(0); } }
public override async Task <int> Handle(AdminUserUpdateFieldCommand request, CancellationToken cancellationToken) { switch (request.Field.ToLower()) { case "name": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Name = request.Value, Updated_At = DateTime.Now })); case "username": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { UserName = request.Value, Updated_At = DateTime.Now })); case "mobile": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Mobile = request.Value, Updated_At = DateTime.Now })); case "password": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Password = Encrypt.Md5By32(request.Value), Updated_At = DateTime.Now })); case "position": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Position = request.Value, Updated_At = DateTime.Now })); case "location": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Location = request.Value, Updated_At = DateTime.Now })); case "company": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Company = request.Value, Updated_At = DateTime.Now })); case "picture": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity() { Picture = request.Value, Updated_At = DateTime.Now })); default: return(0); } }
public async Task <int> UpdateAsync(long id, string field, string value, CancellationToken cancellationToken) { switch (field.ToLower()) { case "icon": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { Icon = value, Updated_At = DateTime.Now }, cancellationToken)); case "url": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { Url = value, Updated_At = DateTime.Now }, cancellationToken)); case "onlycode": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { OnlyCode = value, Updated_At = DateTime.Now }, cancellationToken)); case "weight": return(await db.UpdateAsync <AdminMenuEntity>(c => c.Id == id, c => new AdminMenuEntity() { Weight = value.ToInt(), Updated_At = DateTime.Now }, cancellationToken)); default: return(0); } }
public override async Task <int> Handle(AdminUserUpdateStatusCommand request, CancellationToken cancellationToken) { switch (request.Status) { case Status.Show: return(await db.UpdateAsync <AdminUserEntity>(c => request.Ids.Contains(c.Id), c => new AdminUserEntity { Status = Status.Show, Updated_At = DateTime.Now })); case Status.SoldOut: return(await db.UpdateAsync <AdminUserEntity>(c => request.Ids.Contains(c.Id), c => new AdminUserEntity { Status = Status.SoldOut, Updated_At = DateTime.Now })); case Status.Trash: return(await db.UpdateAsync <AdminUserEntity>(c => request.Ids.Contains(c.Id), c => new AdminUserEntity { Status = Status.Trash, Deleted_At = DateTime.Now })); default: return(0); } }
public override async Task <int> Handle(AdminRoleUpdateFieldCommand request, CancellationToken cancellationToken) { switch (request.Field.ToLower()) { case "name": return(await db.UpdateAsync <AdminRoleEntity>(c => c.Id == request.Id, c => new AdminRoleEntity() { Name = request.Value, Updated_At = DateTime.Now })); default: return(0); } }
public override async Task <int> Handle(AdminUserUpdatePasswordCommand request, CancellationToken cancellationToken) { var admin = await db.Context.AdminUser.FindAsync(request.Id); request.NewPassword = Encrypt.Md5By32(request.NewPassword); request.OldPassword = Encrypt.Md5By32(request.OldPassword); if (!admin.Password.Equals(request.OldPassword)) { throw new Exception("旧密码错误"); } return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity { Password = request.NewPassword })); }
public async Task <int> UpdateAsync(long id, string field, string value, CancellationToken cancellationToken) { switch (field.ToLower()) { case "name": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Name = value, Updated_At = DateTime.Now }, cancellationToken)); case "username": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { UserName = value, Updated_At = DateTime.Now }, cancellationToken)); case "mobile": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Mobile = value, Updated_At = DateTime.Now }, cancellationToken)); case "password": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Password = Encrypt.Md5By32(value), Updated_At = DateTime.Now }, cancellationToken)); case "position": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Position = value, Updated_At = DateTime.Now }, cancellationToken)); case "location": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Location = value, Updated_At = DateTime.Now }, cancellationToken)); case "company": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Company = value, Updated_At = DateTime.Now }, cancellationToken)); case "picture": return(await db.UpdateAsync <AdminUserEntity>(c => c.Id == id, c => new AdminUserEntity() { Picture = value, Updated_At = DateTime.Now }, cancellationToken)); default: return(0); } }
public async Task <Result <int> > UpdateUserAsync([Required][FromBody] AdminUserUpdatePasswordCommand request, CancellationToken cancellationToken = default) { var admin = await db.Context.AdminUser.FindAsync(request.Id); request.NewPassword = Encrypt.Md5By32(request.NewPassword); request.OldPassword = Encrypt.Md5By32(request.OldPassword); if (!admin.Password.Equals(request.OldPassword)) { Failure.Error("旧密码错误"); } var res = await db.UpdateAsync <AdminUserEntity>(c => c.Id == request.Id, c => new AdminUserEntity { Password = request.NewPassword }, cancellationToken); if (res > 0) { return(RestFull.Success(data: res)); } else { return(RestFull.Fail(data: res)); } }